First, we need to import a few libraries:

import matplotlib.pyplot as plt
import seaborn as sns


The dataset that we will use is the iris dataset that we can load using seaborn.

df = sns.load_dataset('iris')

Flip the plot

It is quite straightforward to build a density plot with a 90 degrees orientation thanks to the y argument.

By default, seaborn uses the x argument to plot your graph, but if you explicitly specify that you want it on the y-axis, it will turn 90 degrees.

sns.kdeplot(y=df['sepal_width'], fill=True, color="skyblue")

Going further

This post explains how to flip a density plot with seaborn.

You might be interested in displaying distribution of multiple variables and creating a mirrored density plot.

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 🙏!