Back to Blog

Lazy man's way to good looking charts

Playing with Matplotlib style sheets

Lazy man's way to good looking charts

Team Data21 on matplotlib style visualization

Longing for good looking Matplotlib charts? But feeling too lazy to set each and every parameter manually? Try this time saving tip.

There's a rumor in data visualization community that you can do any conceivable visualization with Matplotlib. It is very likely true but the path to mastery might be challenging to many.

What is the right parameter? Should I apply it to axis, figure or plot? And what is the name of a method for changing the ticks?

Indeed, Matplotlib can be very confusing sometimes even for an advanced user.

I just need good looking charts

How do you create attractive visualizations with minimum effort? Built-in style sheets can come to a rescue.

What is Matplotlib style sheet?

It is a simple way to change style of a chart. Think of it as of CSS for web sites. To put it another way - code for chart creation remains the same and you only change styling by calling one line of code. Neat.

Copy

# Set the style sheet
plt.style.use('fivethirtyeight')

List of all available style sheets

How do you get to know all available style sheets?

Easily. You can list their names.

Copy

# Available styles
print(plt.style.available)

We put together a handy gallery of all built-in Matplotlib styles.

Solarize_Light2
Solarize_Light2
_classic_test_patch
_classic_test_patch
_mpl-gallery
_mpl-gallery
_mpl-gallery-nogrid
_mpl-gallery-nogrid
bmh
bmh
classic
classic
dark_background
dark_background
fast
fast
fivethirtyeight
fivethirtyeight
ggplot
ggplot
grayscale
grayscale
seaborn
seaborn
seaborn-bright
seaborn-bright
seaborn-colorblind
seaborn-colorblind
seaborn-dark
seaborn-dark
seaborn-dark-palette
seaborn-dark-palette
seaborn-darkgrid
seaborn-darkgrid
seaborn-deep
seaborn-deep
seaborn-muted
seaborn-muted
seaborn-notebook
seaborn-notebook
seaborn-paper
seaborn-paper
seaborn-pastel
seaborn-pastel
seaborn-poster
seaborn-poster
seaborn-talk
seaborn-talk
seaborn-ticks
seaborn-ticks
seaborn-white
seaborn-white
seaborn-whitegrid
seaborn-whitegrid
tableau-colorblind10
tableau-colorblind10

Can I create custom styles?

Yes, you can. The best start is to copy existing style sheet. Search for files with .mplstyle extension, usually somewhere in <environment-name>/lib/python3.x/site-packages/matplotlib/mpl-data/stylelib. It is just a text file with parameters.

How do I use my custom style?

Use path to your custom style sheet.

Copy

# Use external style sheet
plt.style.use('./styles/my-custom-style.mplstyle')

How do I reset the stylesheet?

Just call matplotlib.rcdefaults() and you are back at defaults.

Copy

# Reset to defaults
matplotlib.rcdefaults()

Full disclosure: We use custom style sheet for turning data into fine art in Visual pleasures.

Note: We used Matplotlib version 3.5.1 for this tutorial.

Data21.io in your inbox

By subscribing, you agree to receive emails from Data21.io. For details, read our Privacy Policy.