Answers for "matplotlib vertical line plot"

5

python add vertical line in plot

# Basic syntax:
plt.axvline(x_coordinate)

# Example usage:
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()

# Where:
#	- x is the x axis coordinate for the vertical line
#	- ymin is the minimum y-value to show
#	- ymax is the maximum y-value to show
#	- ls is the line style (see also '-', '-.', and ':')
#	- lw is the line width
Posted by: Guest on November-17-2020
1

plt vertical line

plt.axvline(x=0.22058956)
Posted by: Guest on February-13-2021
0

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))

# only one line may be specified; full height
plt.axvline(x=36, color='b', label='axvline - full height')

# only one line may be specified; ymin & ymax spedified as a percentage of y-range
plt.axvline(x=36.25, ymin=0.05, ymax=0.95, color='b', label='axvline - % of full height')

# multiple lines all 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')

# multiple lines with varying ymin and ymax
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')

# single vline with full ymin and ymax
plt.vlines(x=39, ymin=0, ymax=len(xs), colors='green', ls=':', lw=2, label='vline_single - full height')

# single vline with specific ymin and ymax
plt.vlines(x=39.25, ymin=25, ymax=150, colors='green', ls=':', lw=2, label='vline_single - partial height')

# place legend outside
plt.legend(bbox_to_anchor=(1.0, 1), loc='upper left')

plt.show()
Posted by: Guest on March-05-2021

Code answers related to "matplotlib vertical line plot"

Python Answers by Framework

Browse Popular Code Answers by Language