Libraries
First, we need to import a few libraries:
- matplotlib: for plotting
- seaborn: for making the plots prettier
import matplotlib.pyplot as plt
import seaborn as snsDataset
The dataset that we will use is the iris dataset that we can load using seaborn.
df = sns.load_dataset('iris')Shade
Adding a shade to the area under the curve is as simple as setting the 'shade' parameter to True.
sns.set_theme(style="darkgrid")
sns.kdeplot(df['sepal_width'], fill=True)
plt.show()Going further
This post explains how to create a density plot with seaborn.
You might be interested in how to flip a density plot and creating a mirrored density plot.






