Seaborn


Seaborn is a python graphic library built on top of matplotlib. It allows to make your charts prettier with less code. This page provides general seaborn tips. Visit individual chart sections if you need a specific type of plot. Note that most of the matplotlib customization options also work for seaborn.

⏱ Quick start

# library & dataset
import seaborn as sns
df = sns.load_dataset('iris')

# use the function regplot to make a scatterplot
sns.regplot(x=df["sepal_length"], y=df["sepal_width"])

Matplotlib logoBasic vocabulary

Since seaborn is built on top of matplotlib, most of its concepts and vocabulary are still correct. The figure below describes the anatomy of a matplotlib charts. It names all the main components, names that you need to know to understand the documentation properly.

⚠️ Disclaimer: this figure comes from the very complete matplotlib documentation. Have a look at it for a thorough explanation on how this library works.

Anatomy of a matplotlib chart: all the basic vocabulary you need to know to understand the documentation properly

Anatomy of a matplotlib chart: all the basic vocabulary you need to know to understand the documentation properly

🧐 Main seaborn functions

Here is an overview of the most common seaborn functions. It provides a glimpse of they're made for, what are their parameters and links to their official doc.

Todo 😞

Seaborn logoCustomizing titles with Seaborn

Since Seaborn is built on top of Matplotlib, title customization works pretty much the same. A seaborn chart (like the one you get with sns.boxplot()) actually returns a matplotlib axes instance.

This means that you will not be able to use the usual pyplot method plt.title(), but will have to use the corresponding argument for an axes which is ax.set_title(). This is described more in depth in this dedicated post:



Once you've understood how to add a title, customizing it should work the same as for matplotlib:

Seaborn logoCustomizing axis

The exact same concept than explained for titles above applies for axes. So please read the following blogpost about axis customization with matplotlib and apply it to your seaborn chart.

🌈 Seaborn built-in themes

Seaborn comes with a few built-in themes. Those themes are available through the set_style() function. Here is an overview of what is offered.

Todo 😞

If you're interested in a specific type of chart like boxplot or heatmap, I suggest to visit the dedicated section of the gallery. In case you're interested in what seaborn can do, here is a glimpse of what's offered in the gallery 🧐.

Contact


👋 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! 🔥