matplotlib注释多个数据集

发布于 2024-09-08 15:39:29 字数 652 浏览 2 评论 0原文

如果我向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘虞初梦 2024-09-15 15:39:30

您应该将注释视为与轴而不是数据相关联。多个数据集可以绘制在相同的轴上,如您的示例所示,或者您可以在同一个图中具有不同的轴,但是当您使用注释等时,您需要指定要注释的轴。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文