Show Menu

Python - Seaborn Cheat Sheet (DRAFT) by

Seaborn for visualization library

This is a draft cheat sheet. It is a work in progress and is not finished yet.


import seaborn as sns
# If working on a notebook
%matplotlib inline


distri­bution plot
- bin = x
number of bins
- kde = False
remove the line­int­plo­t(x­,y,df)
plot 2 variables
- kind = ''
kind of plot*­irp­lot(df)
plot all vars combin
- hue='categ var'
distin­guish per var
- palette=''
set a color palette­gpl­ot(­df[­'col'])
idea of distri­bution
kde plot
"­kin­d=" E.g.: hex, reg, kde.

CATEGO­RICAL PLOTS­rpl­ot(­x,y,df)
bar plot
- estima­tor=''*
bar values­unt­plo­t(x,df)
bars = count­xpl­ot(­x,y­,,df)
box plot
- hue='categ var'
divide per var
- palette=''
set palette
- orient='h'
horiz. plot­oli­npl­ot(­x,y,df)
violin plot*
- hue='categ var'
divide per var
- palette=''
set palette­rip­plo­t(x­,y,df)
bars = scatter
- jitter = True
add noise
- hue='categ var'
divide per var
- palette=''
set palette
- split = True
split by hue
swarm plot
- hue='categ var'
divide per var
- palette=''
set palette
- split = True
split by hue
** You can alo combine more plots by calling them one after each other.
general categorical form of graph
TIP: when you call a plot function, press
"­shift + tab" to show the parameters needed.
estimator= can be, mean, std, or whatever function. It will display the bars or whatever you choose.
General form, kind=: e.g., point, bar, violin, etc.


What is a violin plot?
It has a similar role of a box and whisker plots. It shows the distri­bution of quanti­tative data across several levels of one (or more) catego­rical variables. The violin plot features a kernel density estimation of the underlying distri­bution.
What is a strip plot?
It will draw a scatte­rplot where one variable is catego­rical. It is also a good complement to a box or violin plot in cases where you want to show all observ­ations along with some repres­ent­ation of the underlying distri­bution.
What is a swarm plot
It is similar to a stripp­lot(), but the points are adjusted (only along the catego­rical axis) so that they don’t overlap. This gives a better repres­ent­ation of the distri­bution of values, although it does not scale as well to large numbers of observ­ations.


heat map plot
- annot = True
add actual values
- cmap=''
set a color palette
- lineco­lor=''
set borders
- linewi­dths=x
set border width­ust­erm­ap(­matrix)
hierarc. clustering
- cmap=''
set a color palette
- standa­rd_­scale = 1
normalise data
Heat map plot needs a correl­ation matrix, or more generally, a matrix. You can use the pivot_­tab­le(­ind­ex,­col­umn­s,v­alues) function to convert a dataframe.

plot all vars combin­ation
- hue='categ var'
divide per var
- palette=''
set palette
g = sns.Pa­irG­rid(df)
set (empty) axis of pairplot­(pl­t.s­catter)
populate axis with some plot­_di­ag(­plt.hist)
set diag plots­_up­per­(pl­t.s­catter)
set upper plots
set lower plots
g = sns.Fa­cet­Gri­d(d­f,c,r)
empty axis
-g =, "­c")
populate axis histograms
-..g.m­ap(­sns.di­stplot, "­c")
populate axis with distplots
now some more complex stuff
- hue='categ var'
divide per var
-g =­­atter, "­c", "­c").a­dd­_le­gend()
g = sns.Jo­int­Gri­d(x­,y,df)
general form of jointp­lot()
g = g.plot­(sn­s.r­egplot, sns.di­stplot)
join two plots


creat reg plot
- hue='categ var'
divide per var
- palette=''
set palette
- markers='' *
set mark shape
- scatte­r_k­ws=­'dict' *
set marker size
create a grid plot
X*X grid
X*X*X grid
- aspect = x
choose ratio
- size = x
set size
marker­s='': e.g., o,v,etc.
scatte­r_k­ws='' e.g.: {'s':100}, it is a call to matplo­tlib. It will be hard to remember how to use these special cases, so no worries, you will have a look online.

STYLE and COLOR­t_s­tyl­e('­dar­kgrid')
apply darkgrid style­t_s­tyl­e('­ticks')
apply ticks style­spine()
remove borders­spi­ne(­lef­t=True)
remove left border­gur­e(f­igs­ize­=(x,x))
choose fig size­t_c­ont­ext­('t­alk') *
set context
set font size
.set_c­ont­ext­(''): e.g.: paper, poster, talk, notebook, etc.