Horizontal density plot

logo of a chart:Density

In a previous post, we saw how to create a density plot with seaborn.

In this post we will see how to create a horizontal density plot with seaborn.

Libraries

First, we need to import a few libraries:

import matplotlib.pyplot as plt
import seaborn as sns

Dataset

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.set_theme(style="darkgrid")
sns.kdeplot(y=df['sepal_width'], fill=True, color="skyblue")
plt.show()

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.

🚨 Grab the Data To Viz poster!


Do you know all the chart types? Do you know which one you should pick? I made a decision tree that answers those questions. You can download it for free!

    dataviz decision tree poster