2

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.

Hooked
  • 84,485
  • 43
  • 192
  • 261
PierreE
  • 675
  • 1
  • 11
  • 23

1 Answers1

4

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()
joon
  • 3,899
  • 1
  • 40
  • 53
Jouni K. Seppänen
  • 43,139
  • 5
  • 71
  • 100