Cheatography

# Matplotlib, seaborn and plotly Cheat Sheet (DRAFT) by Anoikis

Graphical representation of data from kaggle course

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

### Seaborn - 1 feature

 ``_, axes = plt.subplots(nrows=1, ncols=2, figsiz­e=(12, 4))axis[0] = sns.xxx`` put a sns plot in a pyplot figure ``sns.distplot(df['feat']);`` histogram + density of a numeric feature's repart­ition ``sns.boxplot(data=df['feat']);`` simple boxplot ``sns.violinplot(data=df['feat']);`` simple violin plot ``sns.countplot(x='feat',data­=df);`` repart­ition of a categorical feature

### Seaborn - 2 features

 ``sns.he­atm­ap(­matrix)`` heatmap ``sns.jointplot(x=feat1,y=feat2,data=df,kind=['scatter', 'kde'])`` joint plot ``sns.pa­irp­lot(df[feats])`` scatte­rplots matrix ``sns.bo­xpl­ot(x=feat1, y=feat2, data=df, ax=ax)`` boxplot for disjoint groups (x catego­rical) ``sns.vi­oli­npl­ot(x=feat1, y=feat2, data=df, ax=ax)`` violin plot for disjoint groups ``sns.countplot(x='feat1', hue='feat2', data=df);`` repart­ition of a categorical feature according to another one ``sns.lmplot(feat1,feat2, data=df, hue=feat3, fit_reg=False)`` scatte­rplot with color according to category ``sns.factorplot(x=cat1,y=numeric,col=cat2,data=df,kind="box",col_wrap=4,size=, aspect=);`` analyze a quanti­tative variable in 2 catego­rical dimensions at once

### Dimens­ion­allity reduction - t-SNE

 ``from sklear­n.m­anifold import TSNEfrom sklearn.preprocessingimport StandardScaler# Standa­rdize datascaler = Standa­rdS­caler() tab_scaled = scaler.fi­t_t­ran­sform(tab)# Run t-SNEtsne = TSNE(random_state=17)tsne_repr = tsne.fit_transform(tab_scaled)# Show resultsplt.scatter(tsne_repr[:, 0], tsne_r­epr[:, 1], c=df[feat].map(­{False: 'green', True: 'red'}));``

### Plotly

 ``from plotly.of­fline import downlo­ad_­plo­tlyjs, init_n­ote­boo­k_mode, plot, iplotimport plotlyimport plotly.gr­aph­_objs as go`` ``trace0 = go.xxxdata = [trace0, trace1, ...]layout = {'title': title, ..}fig = go.Fig­ure­(da­ta=­data, layout=layout)iplot(fig, show_l­ink­=False)`` general syntax ``trace = go.Sca­tter(x=feat1, y=feat2, name=)`` line ``trace = go.Bar(x=feat1, y=feat2 , name=)`` barchart ``trace = go.Box(y=feat, name=g­enre)`` boxplot ``plotly.offline.plot(fig,filename='file.html',show_link=False)`` Save figure as an html file