在matplotlib中更好地可视化密集的散点图的方法

3
我正在处理来自Reddit的讽刺数据集。两个主要列是“text”和“sarcasm_tag”。我已经向数据框添加了两个列,“positive_score”和“negative_score”。两者都代表正面和负面情感得分。为了可视化得分的分布,我绘制了一个散点图,如下所示:
enter image description here 由于带有“sarcasm_tag == Yes”的文本很少,它隐藏了图表上的许多点。每个标签的单独图如下所示:
enter image description here enter image description here 是否有更好的方法来可视化得分,以便两个类别都能看到?

1
你可以先绘制“否”点,然后再覆盖“是”点。但你可能需要放弃图例或手动调整它。 - wim
好的,这个方法可行。我没想到过这么做,谢谢你。 - Ahmed Dhanani
2
您也可以尝试使用对数刻度来分散聚集在较低值周围的数据。 - morsecodist
2
我认为最好的方法是放弃散点图,转而使用二维直方图。这样,您将能够绘制热力图,从而更好地了解密度,而不是重叠的散点标记。 - lucianopaz
1
你也可以缩小 x_lim 和 y_lim 的范围,使绘图的边距更小! - Lucas
1个回答

2
除了 win解决方案(绘制第二个无点),您还可以调整点的alpha,以为no添加更多颜色。
# Sample data
blue_data = np.random.normal(size=(3000, 2))
red_data = np.random.normal(size=(10, 2))

for blue_point in blue_data:
    plt.plot(blue_point[0], blue_point[1], 'ob')
for red_point in red_data:
    plt.plot(red_point[0], red_point[1], 'or')

enter image description here

“蓝色的 alpha 值为 0.3,红色的 alpha 值为 0.8。”
for blue_point in blue_data:
    plt.plot(blue_point[0], blue_point[1], 'ob', alpha=0.3)
for red_point in red_data:
    plt.plot(red_point[0], red_point[1], 'or', alpha=0.8)

enter image description here

最好的!你可以调整 alpha 直到找到你想要的。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接