简体   繁体   English

Matplotlib图在添加注释时不显示线条

[英]Matplotlib plot does not show lines when adding in annotations

I am trying to figure out how matplotlib annotaitons work and I tried the following: 我试图弄清楚matplotlib注释的工作方式,并尝试了以下方法:

fig = plt.figure()
ax = fig.add_subplot(111, autoscale_on=False, ylim=(1, 9000000))

plt.plot(df['month'], df['France'], label='France')
plt.plot(df['month'], df['Germany'], label='Germany')

ax.annotate('test', xy=(100, 1000), xytext=(3, 1.5),
            arrowprops=dict(facecolor='black', shrink=0.05),
            )

fig.set_size_inches(15, 7)
plt.legend(loc=2)
plt.show()

It is giving me a plot area, but is not showing the lines or the annotations. 它给了我一个绘图区域,但没有显示线条或注释。 Any thoughts? 有什么想法吗?

The following works and gives me a graph, but no annotations, obviously: 以下工作可以给我一个图表,但显然没有注释:

fig = plt.figure()
ax = fig.add_subplot(autoscale_on=False, ylim=(1, 9000000))

plt.plot(df['month'], df['France'], label='France')
plt.plot(df['month'], df['Germany'], label='Germany')

fig.set_size_inches(15, 7)
plt.legend(loc=2)
plt.show()

Have you tried adding arrowstyle'='-' (or '->' , or '<-' or '<->' depending on what type of line or arrow you want) to your arrowprops dictionary? 您是否尝试将arrowstyle'='-' (或'->''<-''<->'取决于所要的线或箭头的类型)添加到arrowprops词典中? Note also that the xy coordinates should be in data units, so it may be that (100, 1000) is not within your axes area (I don't know the range of values of your data.) 另请注意, xy坐标应以数据单位为单位,因此(100, 1000)可能不在轴区域内(我不知道数据值的范围。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM