matplotlib注释多个数据集
如果我向 matplotlib.pyplot.plot 提供多个 x/y 集,annotate
如何决定如何将 xy 值与其中一个集相关联?是否假设所有集合都以相同的方式缩放?
plt.plot(clist, plist, 'g', clist, rlist, 'r', clist, flist, 'b')
plt.annotate("%d chars F=%f" % (threshold_c, threshold_f), xy=(threshold_c, threshold_f),
xytext=(-50, 30), textcoords='offset points',
arrowprops=dict(arrowstyle="->"))
我们似乎有一个很好的答案,但有人要求澄清。
使用默认的 xy=
调用 annotate 具有将注释与图形化的 x/y 对关联起来的效果。当有一个 X 数组和一个 Y 数组时,我很清楚这意味着什么。
对于倍数,我不知道 plot
是否会自动设置多组轴,每个 X/Y 数组一组 - 如果是这样,注释将如何工作。答案解释说,对绘图的一次调用会创建一组轴,尽可能地缩放所有 X/Y 集,因此注释知道该去哪里。
If I feed several x/y sets to matplotlib.pyplot.plot, how does annotate
decide how to correlate the xy value to one of the sets? Is there an assumption that all the sets are scaled the same way?
plt.plot(clist, plist, 'g', clist, rlist, 'r', clist, flist, 'b')
plt.annotate("%d chars F=%f" % (threshold_c, threshold_f), xy=(threshold_c, threshold_f),
xytext=(-50, 30), textcoords='offset points',
arrowprops=dict(arrowstyle="->"))
We seem to have a good answer, but someone asked for clarification.
Calling annotate with the default xy=
has the effect of associating an annotation with a graphed x/y pair. When there's one X array and one Y array, it's obvious to me what that means.
With multiples, I didn't know if plot
was going to automatically set up multiple sets of axes, one for each X/Y array -- and, if so, how annotate was going to work. The answer explains that one call to plot creates one set of axes that scales all the X/Y sets as best it can, and so annotate knows where to go.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将
注释
视为与轴而不是数据相关联。多个数据集可以绘制在相同的轴上,如您的示例所示,或者您可以在同一个图中具有不同的轴,但是当您使用注释等时,您需要指定要注释的轴。You should think of
annotate
as associated with the axes and not the data. Multiple data sets can be plotted on the same axes, as in your example, or you can have different axes in the same plot, but then when you use annotate, etc, you'd want to specify which axes you wanted to annotate.