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

时间:2016-12-28 23:15:55

标签: python matplotlib

我正在使用reddit的sarcasm数据集。两个主要列是textsarcasm_tag。我已在数据框中添加了两列,positive_scorenegative_score。两者分别代表正面和负面情绪的得分。为了可视化分数的这种分布,我绘制了一个散点图,看起来像这样 enter image description here

由于sarcasm_tag == Yes的文字非常少,因此它隐藏了图表上的许多点。两个标签的单独图表如下:
enter image description here

enter image description here

有没有更好的方法可视化分数,以便两个类都可见?

1 个答案:

答案 0 :(得分: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

布鲁斯为0.3阿尔法,红色为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,直到找到你想要的东西。