Examples of how to plot a simple vertical line on a matplotlib figure
Table of contents
Plot a simple vertical line
To plot a simple vertical line on a matplotlib figure, a solution is to use axvline, example
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2*np.pi, 1000)
y1 = np.sin(x)
f = plt.figure()
ax = f.add_subplot(111)
plt.plot(x, y1, '-b', label='sine')
plt.axvline(x=np.pi,color='red')
plt.title('Matplotlib Vertical Line')
plt.xlim(0, 2.0*np.pi)
plt.ylim(-1.5, 1.5)
plt.savefig('matplotlib_vertical_line.png', bbox_inches='tight')
plt.show()
Change the color
plt.axvline(x=np.pi,color='gray')
Dashed line
plt.axvline(x=np.pi,color='gray',linestyle='--')
References
Links | Site |
---|---|
Python matplotlib.pyplot.axvline() Examples | programcreek.com |
How to draw vertical lines on a given plot in matplotlib? | stackoverflow |