标签上的python数据点

我search了很长时间(几个小时就像年龄一样),find了一个非常烦人的(看似基本的)问题的答案,因为我无法find一个恰当的答案,所以我发布了一个问题,并回答它,希望它会节省别人我花了大量的时间在我的noobie密谋技能。

如果你想用python matplotlib来标记你的绘图点

from matplotlib import pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) A = anyarray B = anyotherarray plt.plot(A,B) for i,j in zip(A,B): ax.annotate('%s)' %j, xy=(i,j), xytext=(30,0), textcoords='offset points') ax.annotate('(%s,' %i, xy=(i,j)) plt.grid() plt.show() 

我知道xytext =(30,0)与textcoords一起使用,您使用这些30,0值来定位数据标签点,所以它在0 y轴上,在x轴上它自己的小区域上面。

您需要同时绘制i和j的线,否则您只绘制x或y数据标签。

你得到这样的东西(注意只有标签):
我自己的标有数据点的阴谋

它不理想,还有一些重叠 – 但它比什么都没有,这是我所拥有的。

如何打印(x, y)一次。

 from matplotlib import pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) A = -0.75, -0.25, 0, 0.25, 0.5, 0.75, 1.0 B = 0.73, 0.97, 1.0, 0.97, 0.88, 0.73, 0.54 plt.plot(A,B) for xy in zip(A, B): # <-- ax.annotate('(%s, %s)' % xy, xy=xy, textcoords='data') # <-- plt.grid() plt.show() 

在这里输入图像描述