python - 使用 matplotlib 注释绘图

标签 python matplotlib

我用它来制作一个情节,其中包含特定时刻的内容,例如突出显示

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”这样的水平文本:

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

或者使用文本“line1”并在此范围内显示一个箭头?

最佳答案

以下是如何让箭头显示到跨度:

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()

有关注释的更多信息,请参阅 docs .

以上代码的输出: enter image description here

关于python - 使用 matplotlib 注释绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15148149/

相关文章:

python - n 维中最接近的对

python - 用户警告 : FixedFormatter should only be used together with FixedLocator

python - 关于使用 numpy 或 matplotlib 计算箱线图晶须

python - 如何用虚线绘制渐近线?

python - matplotlib 绘制具有不对称误差线的直方图

python - 这个字符串的编码是什么?

python - 在 pandas 中插入行,其中一列缺少 groupby 中的某些值

python - 获取多列并将它们放入与 Pandas 相同的索引中

python - 即使使用正确的 xpath,Scraper 也会抛出错误

python - 在 64 位 Windows 和 Python 上导入 PyLab 时出错