0% found this document useful (0 votes)
16 views2 pages

Aggialavura Python-Seaborn

Uploaded by

TOP 10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Aggialavura Python-Seaborn

Uploaded by

TOP 10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python - Seaborn Cheat Sheet

by DarioPittera (aggialavura) via cheatography.com/83764/cs/19851/

TO START CATEGO​RICAL PLOTS (cont) MATRIX PLOTS

import seaborn as sns sns.sw​arm​plo​t(x​,y,df) swarm plot sns.he​atm​ap(​df.c​or​r())* heat map plot
# If working on a notebook - hue='categ var' divide per var - annot = True add actual values
%matpl​otlib inline
- palette='' set palette - cmap='' set a color palette

- split = True split by hue - lineco​lor='' set borders


DISTRI​BUTION PLOTS
** You can alo combine more plots by - linewi​dths=x set border width
sns.di​stp​lot​(df​['c​ol']) distri​bution plot
calling them one after each other. sns.cl​ust​erm​ap(​matrix) hierarc. clustering
- bin = x number of bins
sns.factorplot(x,y,df,kind)* - cmap='' set a color palette
- kde = False remove the line general categorical form of graph
- standa​rd_​scale = 1 normalise data
sns.jo​int​plo​t(x​,y,df) plot 2 variables TIP: when you call a plot function, press
Heat map plot needs a correl​ation matrix, or
- kind = '' kind of plot* "​shift + tab" to show the parameters
more generally, a matrix. You can use the
sns.pa​irp​lot(df) plot all vars combin needed.
pivot_​tab​le(​ind​ex,​col​umn​s,v​alues) function
estimator= can be, mean, std, or whatever
- hue='categ var' distin​guish per var to convert a dataframe.
function. It will display the bars or whatever
- palette='' set a color palette
you choose.
GRIDS
sns.ru​gpl​ot(​df[​'col']) idea of distri​bution General form, kind=: e.g., point, bar, violin,
sns.kd​epl​ot(​df[​'col']) kde plot etc. sns.pa​irp​lot(df) plot all vars
combin​ation
"​kin​d=" E.g.: hex, reg, kde.
ON CATEGO​RICAL PLOTS... - hue='categ var' divide per var

CATEGO​RICAL PLOTS What is a violin plot? - palette='' set palette

sns.ba​rpl​ot(​x,y,df) bar plot It has a similar role of a box and whisker g = sns.Pa​irG​rid(df) set (empty)
plots. It shows the distri​bution of quanti​‐ axis of pairplot
- estima​tor=''* bar values
tative data across several levels of one -g.map​(pl​t.s​catter) populate axis
sns.co​unt​plo​t(x,df) bars = count
(or more) catego​rical variables. The with some plot
sns.bo​xpl​ot(​x,y​,,df) box plot violin plot features a kernel density
-g.map​_di​ag(​plt.hist) set diag plots
- hue='categ var' divide per var estimation of the underlying distri​bution.
-g.map​_up​per​(pl​t.s​catter) set upper
- palette='' set palette What is a strip plot? plots
- orient='h' horiz. plot It will draw a scatte​rplot where one -g.map_lower(sns.kdeplot) set lower plots
sns.vi​oli​npl​ot(​x,y,df) violin plot* variable is catego​rical. It is also a good
g = sns.Fa​cet​Gri​d(d​f,c,r) empty axis
complement to a box or violin plot in
- hue='categ var' divide per var -g = g.map(plt .hist, "​c") populate axis
cases where you want to show all
- palette='' set palette histograms
observ​ations along with some repres​ent​‐
sns.st​rip​plo​t(x​,y,df) bars = scatter ation of the underlying distri​bution. -..g.m​ap(​sns.di​stplot, "​c") populate axis
- jitter = True add noise with distplots
What is a swarm plot
- hue='categ var' divide per var now some more complex stuff
It is similar to a stripp​lot(), but the points
- palette='' set palette are adjusted (only along the catego​rical
- split = True split by hue 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.

By DarioPittera (aggialavura) Not published yet. Sponsored by CrosswordCheats.com


Last updated 15th June, 2019. Learn to solve cryptic crosswords!
Page 1 of 2. http://crosswordcheats.com

cheatography.com/aggialavura/
www.dariopittera.com
Python - Seaborn Cheat Sheet
by DarioPittera (aggialavura) via cheatography.com/83764/cs/19851/

GRIDS (cont) STYLE and COLOR

- hue='categ var' divide per var sns.se​t_s​tyl​e('​dar​‐ apply darkgrid


-g = g.map(​plt.sc​atter, "​c", "​c").a​dd​_le​gend() kgrid') style

g = sns.Jo​int​Gri​d(x​,y,df) sns.se​t_s​tyl​e('​ticks') apply ticks style


general form of jointp​lot() sns.de​spine() remove borders
g = g.plot​(sn​s.r​egplot, sns.di​stplot) sns.de​spi​ne(​lef​‐ remove left border
join two plots t=True)
plt.fi​gur​e(f​igs​ize​=(x,x)) choose fig size
REGRESSION PLOTS
sns.se​t_c​ont​ext​('t​alk') set context
sns.lm​plo​t(x​,y,df) creat reg *
plot
sns.set_context set font size
- hue='categ var' divide per (font_scale)
var
.set_c​ont​ext​(''): e.g.: paper, poster, talk,
- palette='' set palette notebook, etc.
- markers='' * set mark
shape
- scatte​r_k​ws=​'dict' * set marker
size
sns.lm​plo​t(x​,y,df,col) create a
grid plot
sns.lmplot(x,y,df,row,col) X*X grid
sns.lmplot(x,y,df,row,col,hue) 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.

By DarioPittera (aggialavura) Not published yet. Sponsored by CrosswordCheats.com


Last updated 15th June, 2019. Learn to solve cryptic crosswords!
Page 2 of 2. http://crosswordcheats.com

cheatography.com/aggialavura/
www.dariopittera.com

You might also like