How to draw an axis in the middle of the figure using Matplotlib

送分小仙女□ 提交于 2019-12-01 08:47:07

问题


I would like to draw a static vertical line that is parallel to the y-axis and which is at the middle of the x-axis. This line should not move when one pan in the figure. My goal is to have this vertical line in the middle of the figure as a reference line. I will have some other figures which represent data that will depend on the x value which is at the middle of the x-axis.


回答1:


The coordinates of the endpoints of that line are (0.5, 0) and (0.5, 1) in axis coordinates:

from matplotlib.lines import Line2D
from matplotlib import pyplot

f=pyplot.figure()
a=f.add_subplot(111)
a.plot([3,1,4,1,5,9,2], color='k') # so you have some content
a.add_line(Line2D([0.5, 0.5], [0, 1], transform=a.transAxes,
                  linewidth=2, color='b'))
pyplot.show()


来源:https://stackoverflow.com/questions/5394527/how-to-draw-an-axis-in-the-middle-of-the-figure-using-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!