使用matplotlib注释某些点 [英] Using matplotlib to annotate certain points

查看:58
本文介绍了使用matplotlib注释某些点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我可以一起整理代码以绘制XY图,但我还需要一些其他东西:

While I can hack together code to draw an XY plot, I want some additional stuff:

  • 从 X 轴向上延伸到指定距离的垂直线
  • 要注释这一点的文本,必须具有接近性(请参见红色文本)
  • 该图为独立图像:一个800个长的序列应占据800个像素的宽度(我希望它与特定图像对齐,因为它是强度图)

如何在mathplotlib中制作这样的图形?

How do I make such a graph in mathplotlib?

推荐答案

你可以这样做:

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
data = (0, 2, 3, 5, 5, 5, 9, 7, 8, 6, 6)
ax.plot(data, 'r-', linewidth=4)

plt.axvline(x=5, ymin=0, ymax=4.0 / max(data), linewidth=4)
plt.text(5, 4, 'your text here')
plt.show()

注意,有些奇怪的是 yminymax 值从 0 到 1 运行,因此需要对轴进行归一化

Note, that somewhat strangely the ymin and ymax values run from 0 to 1, so require normalising to the axis

编辑:OP已修改代码以使其更加面向对象:

The OP has modified the code to make it more OO:

fig = plt.figure()
data = (0, 2, 3, 5, 5, 5, 9, 7, 8, 6, 6)

ax = fig.add_subplot(1, 1, 1)
ax.plot(data, 'r-', linewidth=4)
ax.axvline(x=5, ymin=0, ymax=4.0 / max(data), linewidth=4)
ax.text(5, 4, 'your text here')
fig.show()

这篇关于使用matplotlib注释某些点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆