- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add vertical lines to a distribution plot (sns.distplot) in Matplotlib?
To add vertical lines to a distribution plot, we can take the following steps−
- Create a list of numbers.
- Create an axis using sns.displot().
- Get x and y data of the axis ax.
- Plot a vertical line on the plot.
- Remove the line at the 0th index.
- To display the figure, use show() method.
Example
import seaborn as sns, numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [5, 6, 7, 2, 3, 4, 1, 8, 2] ax = sns.distplot(x, kde=True) x = ax.lines[0].get_xdata() y = ax.lines[0].get_ydata() plt.axvline(x[np.argmax(y)], color='red') ax.lines[0].remove() plt.show()
Output
- Related Articles
- How to remove lines in a Matplotlib plot?
- How to plot overlapping lines in Matplotlib?
- How to change the color and add grid lines to a Python Matplotlib surface plot?
- How to draw axis lines inside a plot in Matplotlib?
- How to create dotted vertical lines in a plot using ggplot2 in R?
- How to add text inside a plot in Matplotlib?
- How to show the Logarithmic plot of a cumulative distribution function in Matplotlib?
- Plot horizontal and vertical lines passing through a point that is an intersection point of two lines in Matplotlib
- How to add a colorbar for a hist2d plot in Matplotlib?
- Fill between two vertical lines in matplotlib
- Getting vertical gridlines to appear in line plot in matplotlib
- How to plot the lines first and points last in Matplotlib?
- How to name different lines in the same plot of Matplotlib?
- How to create two vertical lines on a plot with shaded area in-between using R?
- How to set same color for markers and lines in a Matplotlib plot loop?

Advertisements