Show Menu
Cheatography

Matplotlib, seaborn and plotly Cheat Sheet (DRAFT) by

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 TSNE
from sklearn.preprocessing
import StandardScaler

# Standa­rdize data
scaler = Standa­rdS­caler()
tab_scaled = scaler.fi­t_t­ran­sform(tab)

# Run t-SNE
tsne = TSNE(random_state=17)
tsne_repr = tsne.fit_transform(tab_scaled)

# Show results
plt.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, iplot
import plotly
import plotly.gr­aph­_objs as go
trace0 = go.xxx
data = [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