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
seaborn
offers some specific functions for almost every kind of charts. For instance, regplot()
can be used to build a scatterplot.
Note that no additional code is needed to get the nice grey background with grid and some good defaults for the dots 😍. That's 4 lines of code for a pretty decent chart 🔥!
# 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"])
Basic 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
🧐 Main seaborn
functions
Seaborn
is a wrapper of matplotlib, meaning that when you call a function in seaborn, it calls one or multiple matplotlib functions under the hood.
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.
relplot()
- High-level interface for creating scatter and line plots.scatterplot()
- For creating scatter plots.lineplot()
- For creating line plots.displot()
- For creating distribution plots, including histograms and KDE.histplot()
- For creating histograms.boxplot()
- For creating box plots.violinplot()
- For creating violin plots.heatmap()
- For creating heatmaps.pairplot()
- For creating a grid of scatter plots for pairwise relationships.catplot()
- High-level interface for creating various categorical plots.
Customizing 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
:
Customizing 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.
⭐ Seaborn graph gallery
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 🧐.