Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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

PREVIOUS NEXT
Code Example
Python :: solve sympy 
Python :: keras example 
Python :: pandas change to numeric 
Python :: how to add two numbers in python 
Python :: dataframe to list pyspark 
Python :: python convert string to float array 
Python :: np argmin top n 
Python :: convert price to float python 
Python :: how to append list to list in python 
Python :: import time in python 
Python :: tqdm progress bar python 
Python :: custom save django 
Python :: templateDoesNotExist Django 
Python :: creating data frame in python with for loop 
Python :: f string in python 
Python :: python slice string 
Python :: live plot loss 
Python :: delete an element by value from a list if it made of white spaces python 
Python :: python list length 
Python :: python 2 deprecated 
Python :: convert dictionary keys/values to lowercase in python 
Python :: Change my python working directory 
Python :: tkinter slider 
Python :: login_required on class django 
Python :: count number of spaces in string python 
Python :: pandas replace values based on condition 
Python :: readlines from file python 
Python :: how to check if an object of a certain type python 
Python :: /bin/sh: 1: python: not found 
Python :: list comprehension if 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =