back · main · about · writing · notes · d3 · contact

A quick overview of Seaborn
17 Jul 2017 · 1080 words

Seaborn. A wrapper on top of matplotlib. Used to make plots, and to make them quicker, easier, and more beautiful.

Thank you for your service, matplotlib. Despite your flaws, you’ve guided us this far.

But it’s time to step aside.

Types of Seaborn plots

# Save the JointPlot 
g = sns.jointplot(x="x", y="y", data=df, kind="kde", color="m")

# Use plot_joint to add a scatter plot overlay 
g.plot_joint(plt.scatter, c='w', s=1)

# Or a regression line: 
# Store the PairGrid object
g = sns.PairGrid(iris)

# Change the plots down the diagonal 

# Change the plots down the offdiagonals
g.map_offdiag(sns.kdeplot, cmap="Blues_d", n_levels=6)

A example pointplot using the Titanic dataset.

Miscellaneous functions

Controlling aesthetics

Working with colour

Using colour palettes

Use the cmap  argument to pass across colour palettes to a Seaborn plotting function:

x, y = np.random.multivariate_normal([0, 0], [[1, -.5], [-.5, 1]], size=300).T
cmap = sns.cubehelix_palette(light=1, as_cmap=True)
sns.kdeplot(x, y, cmap=cmap, shade=True)

You can also use the set_palette() function that changes the default matplotlib parameters so the palette is applied to all plots:


back · main · about · writing · notes · d3 · contact