使用matplotlib注释图

编程入门 行业动态 更新时间:2024-10-28 14:28:19
本文介绍了使用matplotlib注释图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用它来绘制包含特定时刻(例如高亮)的图片

I am using this to making a plot with contains in specific moment something such as highlight

plt.axis('normal') plt.axvspan(76, 76, facecolor='g', alpha=1) plt.plot(ts.e1, 'r',linewidth=1.5) plt.ylabel("Anger",fontsize=14,color='blue') plt.ylim(ymax=0.04) plt.xlim(xmax=122) plt.grid(True) plt.title("Anger - Real Events", fontsize=20,color='black') plt.xlabel('minutes', fontsize=14, color='b') plt.show()

我是否可以在其中添加"span 1"之类的水平文本?

Is there any idea if i could add horizontal text like 'span 1' in this:

plt.axvspan(76, 76, facecolor='g', alpha=1)

还是使用文本"line1"并在此范围内显示箭头?

or using the text 'line1' and have a arrow to show in this span?

推荐答案

以下是显示跨度箭头的方法:

Here's how you can have an arrow showing to the span:

import matplotlib.pyplot as plt plt.axvspan(76, 76, facecolor='g', alpha=1) plt.annotate('This is awesome!', xy=(76, 0.75), xycoords='data', textcoords='offset points', arrowprops=dict(arrowstyle="->")) plt.show()

有关注释的更多信息,请参见文档.

For more info about annotate see docs.

以上代码的输出:

更多推荐

使用matplotlib注释图

本文发布于:2023-06-08 23:39:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/591055.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:注释   matplotlib

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!