Custom theme in matplotlib with the morethemes package

logo of a chart:Colours

This post will explain everything you need to know to change the theme of your matplotlib charts with just 1 line of code, using the morethemes package.

Libraries

In order to change the theme of our matplotlib charts, we need to use the morethemes package, that you can install with pip install morethemes.

import pandas as pd
import matplotlib.pyplot as plt
import morethemes as mt

Default chart

morethemes provides a function that generates 4 charts with matplotlib. It's convenient to easily compare themes.

# This displays various matplotlib charts
fig = mt.preview_theme()

You might recognize all the default matplotlib style. Let's improve them with one line of code.

All themes

To apply a theme, you only have to run mt.set_theme("theme_name") before your matplotlib code. "theme_name" is the name of the theme and you can find all available theme here.

Financial Times

To use the Financial Times theme, run mt.set_theme("ft")

mt.set_theme("ft")

# This displays various matplotlib charts
mt.preview_theme()

Wall Street Journal

To use the Wall Street Journal theme, run mt.set_theme("wsj")

mt.set_theme("wsj")

# This displays various matplotlib charts
mt.preview_theme()

The Economist

To use the Economist theme, run mt.set_theme("economist")

mt.set_theme("economist")

# This displays various matplotlib charts
mt.preview_theme()

Urban

To use the Urban theme, run mt.set_theme("urban")

mt.set_theme("urban")

# This displays various matplotlib charts
mt.preview_theme()

Minimal

To use the Minimal theme, run mt.set_theme("minimal")

mt.set_theme("minimal")

# This displays various matplotlib charts
mt.preview_theme()

Other themes

If you want to browse all themes, check out the dedicated documentation.

Going further

Animation with python

Animation

🚨 Grab the Data To Viz poster!


Do you know all the chart types? Do you know which one you should pick? I made a decision tree that answers those questions. You can download it for free!

    dataviz decision tree poster