Background color in seaborn

Change the background color of the panel of the plot

By default, plots made with seaborn have a white background. However, it is possible to change its background color passing a dictionary to the rc argument of the set_style function, as shown below.

import numpy as np
import seaborn as sns

# Data simulation
rng = np.random.RandomState(10)
x = rng.normal(0, 1, size = 100)

# Set the background color
sns.set_style(rc = {'axes.facecolor': 'lightsteelblue'})

# Plot
sns.histplot(x = x)

Setting a background color in seaborn with facecolor

Set the background color with styles or themes

An alternative is setting a theme with axes_style, with set_style or with set_style to modify the global parameters. In this example we are setting the "darkgrid" theme.

Change the background color in seaborn setting a theme style

import numpy as np
import seaborn as sns

# Data simulation
rng = np.random.RandomState(10)
x = rng.normal(0, 1, size = 100)

# Set the style
sns.set_style("darkgrid")

# Plot
sns.histplot(x = x)

Color picker

Use the following color picker to choose a background color or press the “Generate random” button to select a random color.

Better Data Visualizations

A Guide for Scholars, Researchers, and Wonks

Buy on Amazon

See also