如何使用matplotlib解决注释问题

时间:2019-05-07 12:03:49

标签: python matplotlib data-visualization

我目前正在尝试在ylabel的每个标记位置下绘制两个折线图以及一个注释。但是,我面临的一个问题是,只有第一个被绘制而不是在其位置。

这是我的代码:

import matplotlib.pyplot as plt
ax = plt.subplot(111)
first =[0.9122,0.9091,0.9073,0.898,0.888,0.8855,0.8831,0.8837,0.8815,0.8612,0.8628,0.8419,0.8022,0.7805,0.7414]

second=[0.9499,0.9472,0.9421,0.938,0.9401,0.94,0.9417,0.9387,0.9398,0.9395,0.9263,0.9115,0.9089,0.9050,0.8893]

x = [10,20,30,40,50,60,70,80,90,100,200,400,600,800,1000]
xi = [i for i in range(0, len(x))]
plt.xticks(xi, x)

ax.plot(xi, first, marker='x')
ax.plot(xi, second, marker='^')

plt.xlabel('xlabel')
plt.ylabel('ylabel')

ax.legend(loc='upper center',
          bbox_to_anchor=(0.5,  # horizontal
                      1.12),# vertical
          ncol=3, fancybox=True)

for x, y in zip(x, first):
    label = y * 100

    ax.annotate(label,  # this is the text
            (x, y),  # this is the point to label
            textcoords="offset points",  # how to position the text
            xytext=(0, 0),  # distance from text to points (x,y)
            ha='center')

plt.show()

0 个答案:

没有答案