The matplotlib documentation is pretty incomplete, and all you really want to know about its style sheets is what they look like - but they're not shown in an easily comparable way. So here they are!
%matplotlib inline
from matplotlib import pyplot as plt
import numpy as np
sorted(plt.style.available)
['bmh', 'classic', 'dark_background', 'fivethirtyeight', 'ggplot', 'grayscale', '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']
To globally change the style, use plt.style.use(<name>)
. Here, we're going to temporarily switch between them using the context manager form: with plt.style.context((<name>))
. But first let's set up the plots we want to show.
def make_title(s):
return s.replace('-', ' ').replace('_', ' ').title()
def make_plots(style_str=None):
fig, axes_array = plt.subplots(2, 2)
((ax1, ax2), (ax3, ax4)) = axes_array
# sine and cosine line plots
x = np.arange(10)
y_sin = np.sin(x)
y_cos = np.cos(x)
ax1.plot(x, y_sin)
ax1.plot(x, y_cos)
ax1.set_title('sine and cosine line plots')
# a random scatter plot
points1 = np.random.rand(20,2)
points2 = np.random.rand(20,2)
ax2.scatter(points1[:, 0], points1[:, 1])
ax2.scatter(points2[:, 0], points1[:, 1])
ax2.set_title('a random scatter plot')
# a random bar graph
width = 0.4
middles = np.arange(1, 6)
heights1 = np.random.rand(5)
heights2 = np.random.rand(5)
ax3.bar(middles - width, heights1, width)
ax3.bar(middles, heights2, width)
ax3.set_title('a random bar graph')
# a random pie chart
values = np.random.rand(5)
frac_values = values/values.sum()
labels = ['A', 'B', 'C', 'D', 'E']
ax4.pie(frac_values, labels=labels)
ax4.set_title('a random pie chart')
# draw them!
fig.suptitle('{} ({})'.format(make_title(style_str), style_str) if style_str else 'Default Settings', fontsize=20)
fig.subplots_adjust(hspace=0.3)
fig.set_size_inches(10, 10)
plt.show()
import seaborn
!)make_plots()
'seaborn-darkgrid'
)¶with plt.style.context(('seaborn-darkgrid')):
make_plots('seaborn-darkgrid')
'seaborn-whitegrid'
)¶with plt.style.context(('seaborn-whitegrid')):
make_plots('seaborn-whitegrid')
'seaborn-dark-palette'
)¶with plt.style.context(('seaborn-dark-palette')):
make_plots('seaborn-dark-palette')
'seaborn-paper'
)¶with plt.style.context(('seaborn-paper')):
make_plots('seaborn-paper')
'seaborn-talk'
)¶with plt.style.context(('seaborn-talk')):
make_plots('seaborn-talk')
'seaborn-dark'
)¶with plt.style.context(('seaborn-dark')):
make_plots('seaborn-dark')
'seaborn-bright'
)¶with plt.style.context(('seaborn-bright')):
make_plots('seaborn-bright')
'ggplot'
)¶with plt.style.context(('ggplot')):
make_plots('ggplot')
'grayscale'
)¶with plt.style.context(('grayscale')):
make_plots('grayscale')
'seaborn-pastel'
)¶with plt.style.context(('seaborn-pastel')):
make_plots('seaborn-pastel')
'bmh'
)¶with plt.style.context(('bmh')):
make_plots('bmh')
'seaborn-colorblind'
)¶with plt.style.context(('seaborn-colorblind')):
make_plots('seaborn-colorblind')
'seaborn-ticks'
)¶with plt.style.context(('seaborn-ticks')):
make_plots('seaborn-ticks')
'fivethirtyeight'
)¶with plt.style.context(('fivethirtyeight')):
make_plots('fivethirtyeight')
'dark_background'
)¶with plt.style.context(('dark_background')):
make_plots('dark_background')
'seaborn-white'
)¶with plt.style.context(('seaborn-white')):
make_plots('seaborn-white')
'classic'
)¶with plt.style.context(('classic')):
make_plots('classic')
'seaborn-notebook'
)¶with plt.style.context(('seaborn-notebook')):
make_plots('seaborn-notebook')
'seaborn-muted'
)¶with plt.style.context(('seaborn-muted')):
make_plots('seaborn-muted')
'seaborn-deep'
)¶with plt.style.context(('seaborn-deep')):
make_plots('seaborn-deep')
'seaborn-poster'
)¶with plt.style.context(('seaborn-poster')):
make_plots('seaborn-poster')