Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 38 ยท Styling and Themes

Themes, Styles and Plotting Contexts

Control the look of every plot with set_theme: the five styles, the four contexts, font scale, despine, rc overrides and temporary styles with a with block.

Seaborn's biggest visual contribution is not any one chart type; it is that its plots look good without effort. That comes from a theme: a bundle of settings for the background, grid, spines, fonts, line widths and colours. You can change the whole bundle with a single call, or tune individual parts.

This lesson explains the theme system: the five styles (how the axes look), the four contexts (how big everything is), the palette (the colours), and how to override or temporarily switch them.

One call: set_theme

sns.set_theme() takes four main arguments, and each controls one of those layers:

Argument Default Controls
context "notebook" Scale of labels, lines and markers
style "darkgrid" Background, grid lines, spines
palette "deep" Default colour cycle
font, font_scale "sans-serif", 1 Font family and relative text size

Call it once, near the top of your script. It changes Matplotlib's global settings, so plots made by plain Matplotlib afterwards are restyled too (use sns.reset_defaults() or plt.rcdefaults() to undo it).

The five styles

Five axes styles

darkgrid Grey background, white grid. The default.
whitegrid White background with light grid. Good for bars and boxes.
dark Grey background, no grid.
white Plain white, no grid.

ticks adds outward tick marks on a white background.

1 / 2

See them side by side:

Python All five styles

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

sns.axes_style() used in a with block is a temporary style: it applies only to plots created inside the block, then reverts. This is the right tool when one figure in a report needs a different look.

Rules of thumb: whitegrid for bar and box plots (the grid helps reading values), darkgrid for lines and scatter in notebooks, white or ticks for publication figures, dark when the grid would add noise.

Despine and spines

Seaborn defaults to a box around the plot. The top and right spines add no information, so many designers remove them. sns.despine() does it, and you can also offset the axes and trim them to the data range:

Python despine with offset and trim

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

despine() removes the top and right spines by default; pass left=True or bottom=True to remove those too. On figure-level plots use g.despine(...). It works best with the ticks or white styles.

The four contexts: sizes for different media

A plot for a paper, a slide and a poster differ in how big the text and lines should be. Contexts scale those elements without changing the style:

Context Scale Use
paper smallest Journal figures, small prints
notebook default Notebooks and screens
talk larger Slides
poster largest Posters and large displays
Python paper versus talk

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

font_scale on top of a context gives fine control: sns.set_context("talk", font_scale=0.9) keeps the talk line widths but shrinks the text slightly.

Overriding single parameters with rc

Both axes_style() and set_theme() accept rc, a dictionary of Matplotlib parameters that overrides the defaults. List what can be changed with sns.axes_style() (it returns a dictionary):

Python Inspect and override style parameters

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The printed values show what the theme controls; the second part overrides four of them: no top/right spines, dotted grid, bold title. Any Matplotlib rcParam works here. See the Matplotlib styles lesson for the full list of parameters.

Dark mode and the Matplotlib stylesheets

For a dark chart use the darkgrid colours with a dark figure:

Python
sns.set_theme(style="darkgrid", rc={
    "figure.facecolor": "#111827", "axes.facecolor": "#1f2937",
    "axes.labelcolor": "white", "text.color": "white",
    "xtick.color": "white", "ytick.color": "white",
})

Seaborn and Matplotlib's plt.style.use("dark_background") do not mix well: call set_theme() first, then plt.style.use(...), or choose one system for a project.

Good habits

  • Set the theme once in a shared setup cell or module, so every figure matches.
  • Pick the context for the destination (screen, slide, paper) before adjusting sizes manually.
  • Use with sns.axes_style(...) for one-off exceptions instead of calling set_theme repeatedly.
  • Choose the style by the plot type: grids for bars, no grid for heatmaps.
  • Remember that colours come from the palette, which has its own lesson: colour palettes.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which call changes the scale of fonts and lines for a slide deck?

    Contexts (paper, notebook, talk, poster) control the scale of plot elements.
  2. 2. How do you apply a different style to just one figure?

    axes_style works as a context manager and restores the previous settings afterwards.
  3. 3. What does sns.despine() remove by default?

    By default the top and right spines are removed.
  4. 4. Which argument lets you override individual Matplotlib parameters in set_theme?

    rc takes a dictionary of Matplotlib rcParams.

Summary

  • set_theme(context, style, palette, font, font_scale, rc) sets the look globally.
  • Styles: darkgrid, whitegrid, dark, white, ticks. Contexts: paper, notebook, talk, poster.
  • despine(offset, trim) cleans spines; with sns.axes_style(...) styles one figure.
  • rc overrides any single Matplotlib parameter.

Next: Colour Palettes