【问题标题】:What is the best way to represent density in matplotlib without using color?在不使用颜色的情况下在 matplotlib 中表示密度的最佳方法是什么?
【发布时间】:2016-07-16 16:17:55
【问题描述】:

我试图在绘图上表示文档之间的余弦相似度。我有不同类型的文档,它们用不同的颜色表示。我想表示点的密度,但由于颜色标识了文档的类型,我不希望用密度来改变颜色。现在,我有四种不同的颜色,显示红色和绿色很重要;我将来会有6种颜色。我的主要目标是使数据尽可能清晰,如下所示:

虽然这对于具有稀疏数据的绘图很容易做到,但当数据点更集中时(请注意,红点不再可见),则更加困难:

我很想听听有关如何最好地表示这些数据的任何最佳做法或建议。提前致谢!

【问题讨论】:

    标签: python-2.7 matplotlib data-visualization


    【解决方案1】:

    您应该根据稀疏度对数据进行排序,在密集数据之上绘制更稀疏的数据。另外,我通常使用公开圈子:

    import numpy as np
    import matplotlib.pyplot as plt
    
    x1 = np.random.randn(1000,1)
    y1 = np.random.randn(1000,1) # dense data
    x2 = np.random.randn(100,1)
    y2 = np.random.randn(100,1)
    x3 = np.random.randn(10,1)
    y3 = np.random.randn(10,1) # sparse data
    
    fig = plt.figure()
    ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
    
    # plot sparse data after dense data
    ax.scatter(x1, y1, c='none', edgecolors='blue')
    ax.scatter(x2, y2, c='none', edgecolors='green')
    ax.scatter(x3, y3, c='none', edgecolors='red')
    

    如果您的后端支持,请不要忘记使用颜色并考虑使用 alpha 关键字来实现透明度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      • 1970-01-01
      • 2012-07-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多