雖然我可以入侵一起代碼繪製XY曲線,我要一些額外的東西:使用matplotlib來註釋某些點
- 垂直線,從X軸延伸到指定的距離向上
- 文本爲了註釋該點,必須使用接近度(見紅色文本)
- 該圖爲自包含圖像:800長的序列應該佔用800像素的寬度(我希望它與特定圖像對齊,因爲它是強度圖)
如何在mathplotlib中製作這樣的圖表?
雖然我可以入侵一起代碼繪製XY曲線,我要一些額外的東西:使用matplotlib來註釋某些點
如何在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()
。注意,有些奇怪的ymin
和ymax
值從0 to 1
運行,因此需要正常化以軸
編輯:該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()
我不太關注你的第三點,你的意思是你想指定保存的圖像的大小,或者關閉軸或其他東西? – fraxel
在我的具體情況下,我希望它(源圖像的強度投影)適合800 * 600空間,恰好低於800 * 600源圖像 – aitchnyu
[savefig](http://matplotlib.sourceforge.net/api/ figure_api.html?highlight = savefig#matplotlib.figure.Figure.savefig),需要'figsize'和'dpi'參數。所以你可以設置尺寸沒有probs,你也可能想關閉軸。 – fraxel