November 24 2019 updated.
Matplotlib vertical line with text.
The position to place the text.
Example plot with grid lines.
X position in data coordinates of the vertical line.
A dictionary to override the default text properties.
Small additional suggestion say you want to label your line in the legend so that it has some meaning or take advantage of some of the easy to use options in plot then using hold the ylim from the current axis and the repmat is very useful.
Ymin scalar optional default.
Hlines and vlines to plot horizontal and vertical line in matplotlib.
Adding a title to the plot.
Ymax scalar optional default.
Sometimes it is necessary to rotate a text annotation in a matplotlib figure so that it is aligned with a line plotted on the figure axes.
Adding titles to the x and y axis.
Import matplotlib pyplot as plt the data x 1 2 3 4 y 234 124 368 343.
Class matplotlib text annotation text xy xytext none xycoords data textcoords none arrowprops none annotation clip none kwargs source bases.
Should be between 0 and 1 0 being the bottom of the plot 1 the top of the plot.
The underlying object that handles text is matplotlib text text ensuring that all text handling methods are consistent.
The coordinate system can be changed using the transform parameter.
X position in data coordinates of the vertical line.
Matplotlib text classes for including text in a figure.
Axhline and axvline to plot horizontal and vertical lines in matplotlib.
Axes annotation takes an argument rotation to allow a text label to be rotated and a naive implementation might be as follows.
The created text instance.
By default this is in data coordinates.
The major items we use text for on a plot are.
You can also make multiple vertical lines with some spacing using this technique.
An annotation is a text that can refer to a specific position xy.
If fontdict is none the defaults are determined by rcparams.
Conclusion of drawing horizontal and vertical lines in matplotlib in this tutorial we will introduce two methods to draw horizontal and vertical lines in matplotlib.
Should be between 0 and 1 0 being the bottom of the plot 1 the top of the plot.