I would like to draw a vertical line with Matpotlib and I\'m using axvline
, but it doesn\'t work.
import sys
import matplotlib
matplotlib.use(\
x
as a list, while matplotlib.pyplot.axvline only permits one location.
x=37
x=[37, 38, 39]
fig, ax = plt.subplots()
, then replace plt.vlines
or plt.axvline
with ax.vlines
or ax.axvline
, respectively.import numpy as np
import matplotlib.pyplot as plt
xs = np.linspace(1, 21, 200)
plt.vlines(x=[37, 38, 39], ymin=0, ymax=len(xs), colors='purple', ls='--', lw=2, label='vline_multiple')
plt.vlines(x=40, ymin=0, ymax=len(xs), colors='green', ls=':', lw=2, label='vline_single')
plt.axvline(x=36, color='b', label='avline')
plt.legend()
plt.show()