Seaborn style in matplotlib

Gemain Salvato-Vallverdu germain.vallverdu@univ-pau.fr

Matplotlib provides several styles in oder to produce aesthetic plots. Among them, there is a serie of seaborn styles from the python library of the same name.


In [1]:
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
seaborn_style = [style for style in matplotlib.style.available if "seaborn" in style]
seaborn_style


Out[1]:
['seaborn-talk',
 'seaborn-poster',
 'seaborn-muted',
 'seaborn-colorblind',
 'seaborn-white',
 'seaborn-paper',
 'seaborn-whitegrid',
 'seaborn-pastel',
 'seaborn-dark-palette',
 'seaborn-bright',
 'seaborn-notebook',
 'seaborn-darkgrid',
 'seaborn-ticks',
 'seaborn-dark',
 'seaborn-deep']

Actually, seaborn styles can be divided into 3 categories :

  • color palette
    • seaborn-bright
    • seaborn-colorblind
    • seaborn-dark-palette
    • seaborn-deep
    • seaborn-muted
    • seaborn-pastel
  • themes mainly about elements' frame
    • seaborn-dark(grid) => dark theme with or without grid
    • seaborn-white(grid) => white theme with or without grid
    • seaborn-ticks => white theme with ticks * fonts and sizes
    • seaborn-notebook
    • seaborn-paper * seaborn-poster
    • seaborn-talk

Thus one should select one of each category to have a full theme.


In [2]:
import numpy as np

Color palettes

Hereafter, the 6 available color palettes are used in order to plot 6 lines.


In [3]:
colors = {
    "seaborn-bright": ['003FFF', '03ED3A', 'E8000B', '8A2BE2', 'FFC400', '00D7FF'],
    "seaborn-colorblind": ['0072B2', '009E73', 'D55E00', 'CC79A7', 'F0E442', '56B4E9'],
    "seaborn-dark-palette": ['001C7F', '017517', '8C0900', '7600A1', 'B8860B', '006374'],
    "seaborn-deep": ['4C72B0', '55A868', 'C44E52', '8172B2', 'CCB974', '64B5CD'],
    "seaborn-muted": ['4878CF', '6ACC65', 'D65F5F', 'B47CC7', 'C4AD66', '77BEDB'],
    "seaborn-pastel": ['92C6FF', '97F0AA', 'FF9F9A', 'D0BBFF', 'FFFEA3', 'B0E0E6']    
}
f, axes = plt.subplots(2, 3, figsize=(12, 6), sharex=True, sharey=True)
x = np.linspace(0, 1, 100)
for ax, cname in zip(axes.flat, colors):
    for i, color in enumerate(colors[cname]):
        ax.plot(x, (i+1)*x**2 + i, color="#" + color, linewidth=5)
        ax.set_title(cname)


Themes about fonts and sizes

The four themes : poster, talk, notebook and paper, mainly modify the sizes of fonts, lines, figure, ticks etc ... The poster theme set the largest sizes and the paper theme the smallest.

On the examples below, the main differences are from the fontsizes.


In [4]:
base = "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/mpl-data/stylelib/"
styles = ["seaborn-notebook", "seaborn-paper", "seaborn-poster", "seaborn-talk"]
f, axes = plt.subplots(2, 2, figsize=(6, 6))
x = np.linspace(0, 1, 100)
for ax, style in zip(axes.flat, styles):
    rc = matplotlib.style.core.rc_params_from_file(base + style + ".mplstyle")
    matplotlib.rcParams.update(rc)
    for i in range(6):
        ax.plot(x, (i+1)*x**2 + i, linewidth=5)
        ax.set_title(style)
plt.tight_layout()


Complete themes

Now we will plot the same plots using either the dark theme either the white theme with one of the color palette.

Using the dark theme


In [5]:
matplotlib.style.use(["seaborn-darkgrid", "seaborn-colorblind", "seaborn-notebook"])
x = np.linspace(0, 1, 100)
for i in range(6):
    plt.plot(x, (i+1)*x**2 + i)
plt.title("With the darkgrid, colorblind and notebook styles")


Out[5]:
<matplotlib.text.Text at 0x1095433c8>

Using the white theme

The ticks style add the ticks to the white style. Nevertheless, whitegrid and ticks style are not consistant as the former remove the ticks and add a grid and the latter remove the grid and add the ticks.


In [6]:
matplotlib.style.use(["seaborn-whitegrid", "seaborn-deep", "seaborn-notebook"])
x = np.linspace(0, 1, 100)
for i in range(6):
    plt.plot(x, (i+1)*x**2 + i)
plt.title("With the whitegrid, deep and notebook styles")


Out[6]:
<matplotlib.text.Text at 0x109763748>

Same as above, without the grid but with ticks and paper size.


In [7]:
matplotlib.style.use(["seaborn-ticks", "seaborn-deep", "seaborn-paper"])
x = np.linspace(0, 1, 100)
for i in range(6):
    plt.plot(x, (i+1)*x**2 + i)
plt.title("With the white, ticks, deep and notebook styles")


Out[7]:
<matplotlib.text.Text at 0x109b58c18>