Seaborn Cheat Sheet

Introduction

Seaborn is a popular data visualization library in Python that is used to create beautiful and informative statistical graphics. It is built on top of the Matplotlib library and provides a high-level interface for creating attractive and informative visualizations. Seaborn is widely used in data science, machine learning, and statistical analysis.

To help users get started with Seaborn, we’ve created cheat sheet that provides a quick reference guide to the most commonly used functions and methods in Seaborn. The cheat sheet is designed to be a handy reference guide for users who are new to Seaborn or who need a quick reminder of the syntax and parameters of various functions.

This Seaborn cheat sheet covers a wide range of topics, including data visualization, statistical plotting, color palettes, and data manipulation. It includes examples of how to create various types of plots, such as scatter plots, line plots, bar plots, and heatmaps.

Importing Seaborn

import seaborn as sns

Setting the Style

sns.set_style(style=None, rc=None)
ParameterDescription
styleName of style to use, or None to reset to default
rcDictionary of parameter values to set

Loading Datasets

sns.load_dataset(name, cache=True, data_home=None, **kws)
ParameterDescription
nameName of dataset to load
cacheWhether to cache downloaded file
data_homeDirectory to cache downloaded files
kwsAdditional keyword arguments to pass to pandas.read_csv()

Plotting Functions

Relational Plots

sns.relplot(x=None, y=None, hue=None, size=None, style=None, data=None, kind='scatter', **kwargs)
ParameterDescription
xColumn name for x-axis
yColumn name for y-axis
hueColumn name for color grouping
sizeColumn name for size grouping
styleColumn name for style grouping
dataDataFrame to use
kindType of plot to draw
kwargsAdditional keyword arguments to pass to the plotting function

Categorical Plots

sns.catplot(x=None, y=None, hue=None, data=None, kind='strip', **kwargs)
ParameterDescription
xColumn name for x-axis
yColumn name for y-axis
hueColumn name for color grouping
dataDataFrame to use
kindType of plot to draw
kwargsAdditional keyword arguments to pass to the plotting function

Distribution Plots

sns.displot(x=None, y=None, hue=None, data=None, kind='hist', **kwargs)
ParameterDescription
xColumn name for x-axis
yColumn name for y-axis
hueColumn name for color grouping
dataDataFrame to use
kindType of plot to draw
kwargsAdditional keyword arguments to pass to the plotting function

Regression Plots

sns.lmplot(x=None, y=None, hue=None, data=None, **kwargs)
ParameterDescription
xColumn name for x-axis
yColumn name for y-axis
hueColumn name for color grouping
dataDataFrame to use
kwargsAdditional keyword arguments to pass to the plotting function

Matrix Plots

sns.heatmap(data=None, **kwargs)
ParameterDescription
dataDataFrame to use
kwargsAdditional keyword arguments to pass to the plotting function

Customizing Plots

Color Palettes

sns.color_palette(palette=None, n_colors=None, desat=None)
ParameterDescription
paletteName of palette to use
n_colorsNumber of colors in the palette
desatSaturation factor for colors

Color Maps

sns.color_palette(palette=None, n_colors=None, desat=None)
ParameterDescription
paletteName of palette to use
n_colorsNumber of colors in the palette
desatSaturation factor for colors

Axis Labels

ax.set(xlabel=None, ylabel=None)
ParameterDescription
xlabelLabel for x-axis
ylabelLabel for y-axis

Titles

ax.set_title(label=None, fontdict=None, loc=None, pad=None, **kwargs)
ParameterDescription
labelText for title
fontdictDictionary of font properties
locLocation of title
padPadding between title and plot
kwargsAdditional keyword arguments to pass to matplotlib.text.Text()

Legends

ax.legend(*args, **kwargs)
ParameterDescription
argsArtist objects to include in legend
kwargsAdditional keyword arguments to pass to matplotlib.legend.Legend()

Conclusion

This cheat sheet provides an overview of the most commonly used functions and parameters in Seaborn. For more information, please refer to the official Seaborn documentation.

Reference:

https://seaborn.pydata.org/