How to plot a histogram but split it by categories using Seaborn in Python

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

It might come in handy to plot a histogram to visualize our dataset but split it by a certain category.

Here we use the example of irises species

import seaborn as sns

# We set the theme
sns.set_theme(style="darkgrid")

# We get the sample dataset
df = sns.load_dataset("iris")

# We make a histogram but split by categories
fig = sns.displot(
    df, x="sepal_length", col="species",
    binwidth=1, height=3,
)
How to plot a histogram but split by categories using Seaborn

Using the seaborn.displot() function we will plot a histogram by default. We can specify which variable we want to analyze with the x parameter.

Here we will analyze the sepal_length variable and split it by column which will be species in our case.

The result

Here is how to plot a histogram but split by category

Here you are! You now know how to plot a histogram but split it by categories using Seaborn in Python!

More on seaborn

If you want to know more about how to use Seaborn, etc... check out the other articles I wrote on the topic, just here :

Seaborn - The Python You Need
We gathered the only Python essentials that you will probably ever need.

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.