Apply a style sheet to Matplotlib


Matplotlib comes with 26 pre-built style sheets. You can apply them to any kind of Matplotlib chart thanks to the use_style() function. It allows to create beautiful viz out of the box.

List of themes

The list of available matplotlib themes is stored in a list called plt.style.available. There are 26 of them.

import matplotlib.pyplot as plt
plt.style.available
['Solarize_Light2',
 '_classic_test_patch',
 'bmh',
 'classic',
 'dark_background',
 'fast',
 'fivethirtyeight',
 'ggplot',
 'grayscale',
 'seaborn',
 'seaborn-bright',
 'seaborn-colorblind',
 'seaborn-dark',
 'seaborn-dark-palette',
 'seaborn-darkgrid',
 'seaborn-deep',
 'seaborn-muted',
 'seaborn-notebook',
 'seaborn-paper',
 'seaborn-pastel',
 'seaborn-poster',
 'seaborn-talk',
 'seaborn-ticks',
 'seaborn-white',
 'seaborn-whitegrid',
 'tableau-colorblind10']

Scatterplot

The scatterplot section of the gallery explains in depth how to build a basic scatterplot with matplotlib. It is pretty straightforward thanks to the plot() function.

# Create a dataset:
import numpy as np
import pandas as pd
df=pd.DataFrame({'x': range(1,101), 'y': np.random.randn(100)*15+range(1,101) })
 
# plot
plt.plot( 'x', 'y', data=df, linestyle='none', marker='o')
plt.show()

Apply a theme

Now, let's make this chart a bit prettier thanks to the style called fivethirtyheight. In case you don't know it already, FiveThirtyHeight is an online newspaper that often displays some very nice dataviz articles.

plt.style.use('fivethirtyeight')
plt.plot( 'x', 'y', data=df, linestyle='none', marker='o')
plt.title('Scatterplot with the five38 theme', fontsize=12)
plt.show()

Apply the style on a barchart

You can apply the same exact tip for any kind of chart to make it look better. Here is a barchart example coming from the barchart section of the gallery. It uses the dark_background theme to demo another type of customization.

# create dataset
height = [3, 12, 5, 18, 45]
bars = ('A', 'B', 'C', 'D', 'E')
y_pos = np.arange(len(bars))
 
# Create horizontal bars
plt.barh(y_pos, height)
 
# Create names on the x-axis
plt.yticks(y_pos, bars)
 
# Show graphic
plt.style.use('dark_background')
plt.show()

Colors

Interactivity

Animation with python

Animation

Cheat sheets

Caveats

3D

Contact & Edit

👋 This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message onTwitter, or send an email pasting yan.holtz.data with gmail.com.

This page is just a jupyter notebook, you can edit it here. Please help me making this website better 🙏!

Violin

Density

Histogram

Boxplot

Ridgeline

Scatterplot

Heatmap

Correlogram

Bubble

Connected Scatter

2D Density

Barplot

Spider / Radar

Wordcloud

Parallel

Lollipop

Circular Barplot

Treemap

Venn Diagram

Donut

Pie Chart

Dendrogram

Circular Packing

Line chart

Area chart

Stacked Area

Streamgraph

Timeseries with python

Timeseries

Map

Choropleth

Hexbin

Cartogram

Connection

Bubble

Chord Diagram

Network

Sankey

Arc Diagram

Edge Bundling

Colors

Interactivity

Animation with python

Animation

Cheat sheets

Caveats

3D