Example 1: horizontal line matplotlib python
import matplotlib.pyplot as plt
plt.axhline(0)
Example 2: python add vertical line in plot
plt.axvline(x_coordinate)
import matplotlib.pyplot as plt
plt.figure(figsize=(5, 5))
plt.axvline(x=10, ymin=0.10, ymax=0.70, color='b', ls='--', lw=1.5, label='axvline - % of full height')
plt.legend(bbox_to_anchor=(1.0, 1), loc='best')
plt.show()
Example 3: vertical line in matplotlib
xposition = [0.3, 0.4, 0.45]
for xc in xposition:
plt.axvline(x=xc, color='k', linestyle='--')
Example 4: plt vertical line
plt.axvline(x=0.22058956)
Example 5: how to add vertical line on subplot in matplotlib
import numpy as np
import matplotlib.pyplot as plt
xs = np.linspace(1, 21, 200)
plt.figure(figsize=(10, 7))
plt.axvline(x=36, color='b', label='axvline - full height')
plt.axvline(x=36.25, ymin=0.05, ymax=0.95, color='b', label='axvline - % of full height')
plt.vlines(x=[37, 37.25, 37.5], ymin=0, ymax=len(xs), colors='purple', ls='--', lw=2, label='vline_multiple - full height')
plt.vlines(x=[38, 38.25, 38.5], ymin=[0, 25, 75], ymax=[200, 175, 150], colors='teal', ls='--', lw=2, label='vline_multiple - partial height')
plt.vlines(x=39, ymin=0, ymax=len(xs), colors='green', ls=':', lw=2, label='vline_single - full height')
plt.vlines(x=39.25, ymin=25, ymax=150, colors='green', ls=':', lw=2, label='vline_single - partial height')
plt.legend(bbox_to_anchor=(1.0, 1), loc='upper left')
plt.show()
Example 6: add vertical line in plot python
pythonCopymatplotlib.pyplot.axvline(x=0, ymin=0, ymax=1, hold=None, **kwargs)