2012-05-08 39 views
3

虽然我可以入侵一起代码绘制XY曲线,我要一些额外的东西:使用matplotlib来注释某些点

  • 垂直线,从X轴延伸到指定的距离向上
  • 文本为了注释该点,必须使用接近度(见红色文本)
  • 该图为自包含图像:800长的序列应该占用800像素的宽度(我希望它与特定图像对齐,因为它是强度图)

enter image description here

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

+0

我不太关注你的第三点,你的意思是你想指定保存的图像的大小,或者关闭轴或其他东西? – fraxel

+0

在我的具体情况下,我希望它(源图像的强度投影)适合800 * 600空间,恰好低于800 * 600源图像 – aitchnyu

+0

[savefig](http://matplotlib.sourceforge.net/api/ figure_api.html?highlight = savefig#matplotlib.figure.Figure.savefig),需要'figsize'和'dpi'参数。所以你可以设置尺寸没有probs,你也可能想关闭轴。 – fraxel

回答

7

你可以这样说:

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 to 1运行,因此需要正常化以轴

enter image description here


编辑:该OP已修改代码,使其更多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() 
+0

下个工作日将试用! – aitchnyu

+0

fraxel,请看看这个编辑过的版本 – aitchnyu