Skip to content

Plot Styles

Plot Styles

Colors, font sizes, line thickness, all have default values in Matplotlib. In addition to the default style for these plot attributes, additional styles are available. To use the default style, either don't specify a style at all or use the line plt.style.use('default'). If you want to apply a different style to a plot use the line:

plt.style.use('style')

The 'style' is supplied to the method as a string, surrounded by quotes.

The code below builds a plot with 'fivethirtyeight' style, a style similar to the plots on fivethirtyeight.com.

In [1]:
import numpy as np
import matplotlib.pyplot as plt
# if using a Jupyter notebook, include:
%matplotlib inline

x = np.linspace(0, 10) fig, ax = plt.subplots()

plt.style.use('fivethirtyeight')

for n in range(-20,30,10): ax.plot(x, np.cos(x) + np.random.randn(50) + n)

ax.set_title("'fivethirtyeight' style")

plt.show()

There are many different styles available. You can list the available Matplotlib styles with the command:
In [2]:
for style in plt.style.available:
    print(style)

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

The code section below displays a couple of Matplotlib's available plot styles including the 'default', 'seaborn' and the older Matplotlib 'classic' style.
In [3]:
def pl(ax,st):
    x = np.linspace(0, 10)
    for n in range(-20,30,10):
        ax.plot(x, np.cos(x) + np.random.randn(50) + n) 

def his(ax): x = np.random.randn(50) ax.hist(x)

def lb(ax,s): ax.text(0.2,0.5,s, fontsize=14) ax.xaxis.set_ticklabels([],[]) ax.yaxis.set_ticklabels([],[])

def make_fig(st): with plt.style.context(st): fig,[ax1,ax2,ax3]=plt.subplots(1,3,figsize=(9,1.5)) lb(ax1,st) his(ax2) pl(ax3,st)

s = ['default','fivethirtyeight','seaborn', 'Solarize_Light2','classic']

for st in s: make_fig(st)

plt.show()