Basic density plot with seaborn

logo of a chart:Density

With seaborn, a density plot is made using the kdeplot function. It only takes one numerical variable as input, as presented in the example below.

How to build a basic density chart with Python and Seaborn.

# libraries & dataset
import seaborn as sns
import matplotlib.pyplot as plt
  
sns.set_theme(style="darkgrid")
df = sns.load_dataset('iris')
 
# Make default density plot
sns.kdeplot(df['sepal_width'])
plt.show()

Cumulative density plot

# libraries & dataset
import seaborn as sns
import matplotlib.pyplot as plt
  
sns.set_theme(style="darkgrid")
df = sns.load_dataset('iris')
 
# Make default density plot
sns.kdeplot(df['sepal_width'], cumulative=True)
plt.show()

Contact & Edit


👋 This document is a work by Yan Holtz. You can contribute on github, send me a feedback on twitter or subscribe to the newsletter to know when new examples are published! 🔥

This page is just a jupyter notebook, you can edit it here. Please help me making this website better 🙏!