【问题标题】:Label data when doing a scatter plot in python在python中做散点图时标记数据
【发布时间】:2017-05-12 00:31:52
【问题描述】:

我想标记我在 python 中绘制的每个点,但我没有找到合适的方法。

假设我有两个名为 abn 元素列表,我以这种方式打印它们:

    plt.figure()
    plt.grid()
    plt.plot(a , b , 'bo')
    plt.show()

我想用“变量 k”标记每个点,k 的范围显然从 1n。 感谢您的宝贵时间

【问题讨论】:

标签: python matplotlib label


【解决方案1】:

您可以使用label 绘图参数

x = np.random.random(3)
y = np.random.random(3)
z = np.arange(3)
colors = ["red", "yellow", "blue"]
c = ["ro", "yo", "bo"]

for i in z:
    plt.plot(x[i], y[i], c[i], label=colors[i] + ' ' + str(i))
plt.legend()

【讨论】:

    【解决方案2】:

    这是我发现的最好的方法:

    plt.figure()
    plt.scatter(a,b)
    labels = ['Variable {0}'.format(i+1) for i in range(n)]
    for i in range (0,n):
        xy=(a[i],b[i])
        plt.annotate(labels[i],xy)
    plt.plot()
    

    更多信息:Matplotlib: How to put individual tags for a scatter plot

    【讨论】:

      猜你喜欢
      • 2022-01-16
      • 2016-02-29
      • 1970-01-01
      • 2016-04-28
      • 1970-01-01
      • 2019-09-30
      • 2019-12-03
      • 2012-10-25
      • 2017-04-20
      相关资源
      最近更新 更多