Change Background Color in Seaborn: 7 Easy Ways With Examples

Change Background Color in Seaborn, A well-designed chart can make data much easier to understand. While Seaborn provides attractive default styles, you may eventually want to customize the background color of a Seaborn plot to match a presentation, dashboard, report, website, or brand style.

The good news is that changing the background color is straightforward. Because Seaborn is built on top of Matplotlib, you can customize both the plot area and the entire figure background using Matplotlib’s configuration options.

In this tutorial, you’ll learn how to change Seaborn background colors using named colors, HEX codes, RGB-style colors, and Matplotlib axes. You’ll also see how to create dark-themed charts, transparent backgrounds, and reusable custom styles.

What Is the Difference Between the Axes and Figure Background?

Before changing colors, it helps to understand the two main areas of a Seaborn chart.

Axes background: This is the area inside the actual plotting region where your data points, lines, bars, or other graphics appear.

Figure background: This is the area surrounding the axes, including the space around the plot.

For example, you can make the axes light blue while keeping the surrounding figure light green.

sns.set(
    rc={
        "axes.facecolor": "lightblue",
        "figure.facecolor": "lightgreen"
    }
)

The two settings serve different purposes:

figure.facecolor
└── Entire figure

    axes.facecolor
    └── Plotting area

Change the Seaborn Plot Background Color

The simplest approach is to use sns.set() with the rc parameter.

Here’s a complete example:

import seaborn as sns
import matplotlib.pyplot as plt

x = [1, 2, 2, 3, 5, 6, 6, 7, 9, 10, 12, 13]
y = [8, 8, 10, 12, 13, 15, 18, 15, 19, 22, 24, 29]

sns.set(
    rc={
        "axes.facecolor": "lightblue",
        "figure.facecolor": "lightgreen"
    }
)

sns.scatterplot(x=x, y=y)

plt.show()

Here:

  • axes.facecolor controls the background inside the plotting area.
  • figure.facecolor controls the area outside the plotting axes.
  • plt.show() displays the finished chart.

Use the Same Background Color for the Entire Plot

In many dashboards and reports, you may want the entire chart to have a consistent background.

You can assign the same color to both settings:

import seaborn as sns
import matplotlib.pyplot as plt

x = [1, 2, 2, 3, 5, 6, 6, 7, 9, 10, 12, 13]
y = [8, 8, 10, 12, 13, 15, 18, 15, 19, 22, 24, 29]

sns.set(
    rc={
        "axes.facecolor": "lightblue",
        "figure.facecolor": "lightblue"
    }
)

sns.scatterplot(x=x, y=y)

plt.show()

This produces a chart where both the plotting region and the surrounding figure use the same light-blue background.

This style can work particularly well for dashboards and presentation graphics where you want the chart to look like one continuous visual element.

Change the Background Using a HEX Color

You aren’t limited to predefined color names such as "lightblue" or "lightgreen".

For precise control, use a HEX color code.

For example:

import seaborn as sns
import matplotlib.pyplot as plt

x = [1, 2, 2, 3, 5, 6, 6, 7, 9, 10, 12, 13]
y = [8, 8, 10, 12, 13, 15, 18, 15, 19, 22, 24, 29]

sns.set(
    rc={
        "axes.facecolor": "#33FFA2",
        "figure.facecolor": "lightgrey"
    }
)

sns.scatterplot(x=x, y=y)

plt.show()

The #33FFA2 value specifies the background color of the plotting area.

HEX colors are particularly useful when you’re trying to match an organization’s brand colors.

Use Matplotlib’s set_facecolor() Method

Another flexible approach is to work directly with the Matplotlib figure and axes.

This gives you more control over individual components of the chart.

import matplotlib.pyplot as plt
import seaborn as sns

x = [1, 2, 2, 3, 5, 6, 6, 7, 9, 10, 12, 13]
y = [8, 8, 10, 12, 13, 15, 18, 15, 19, 22, 24, 29]

figure, axis = plt.subplots()

axis.set_facecolor("#EAF4FF")
figure.patch.set_facecolor("#D9EAF7")

sns.scatterplot(x=x, y=y, ax=axis)

plt.show()

Here:

axis.set_facecolor()

changes the axes background, while:

figure.patch.set_facecolor()

changes the figure background.

This approach is useful when you’re working with multiple plots and want each figure to have different styling.

Create a Dark Seaborn Plot

Dark backgrounds are popular in dashboards, monitoring applications, presentations, and developer-focused interfaces.

You can create one by combining a dark figure background with a dark axes background.

import matplotlib.pyplot as plt
import seaborn as sns

x = [1, 2, 2, 3, 5, 6, 6, 7, 9, 10, 12, 13]
y = [8, 8, 10, 12, 13, 15, 18, 15, 19, 22, 24, 29]

sns.set_theme(style="darkgrid")

figure, axis = plt.subplots()

axis.set_facecolor("#1E1E1E")
figure.patch.set_facecolor("#121212")

sns.scatterplot(
    x=x,
    y=y,
    ax=axis
)

axis.set_title("Sales Performance")

plt.show()

For dark charts, you should also pay attention to text, gridlines, and data colors so that everything remains readable.

Change Only the Axes Background

Sometimes you want to keep the overall figure white but change the plotting area.

In that situation, modify only axes.facecolor:

import seaborn as sns
import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5, 6]
y = [8, 13, 14, 11, 16, 22]

sns.set(
    rc={
        "axes.facecolor": "#FFF3CD"
    }
)

sns.lineplot(x=x, y=y)

plt.show()

The area surrounding the plot remains unchanged, while the plotting region gets the specified color.

Change the Background of a Bar Chart

The same technique works with Seaborn bar charts.

import matplotlib.pyplot as plt
import seaborn as sns

months = ["Jan", "Feb", "Mar", "Apr", "May"]
sales = [120, 150, 180, 160, 210]

figure, axis = plt.subplots(figsize=(8, 5))

axis.set_facecolor("#F5F7FA")
figure.patch.set_facecolor("#E8EEF5")

sns.barplot(
    x=months,
    y=sales,
    ax=axis
)

axis.set_title("Monthly Sales")
axis.set_xlabel("Month")
axis.set_ylabel("Sales")

plt.show()

Using an explicit axis makes the code easier to maintain, especially when you’re creating several charts in a Python data-analysis workflow.

Change the Background of a Heatmap

Heatmaps can also be customized.

For example:

import matplotlib.pyplot as plt
import seaborn as sns

data = [
    [10, 20, 30],
    [15, 25, 35],
    [20, 30, 40]
]

figure, axis = plt.subplots(figsize=(7, 5))

axis.set_facecolor("#F2F2F2")
figure.patch.set_facecolor("#FFFFFF")

sns.heatmap(
    data,
    annot=True,
    fmt="d",
    ax=axis
)

axis.set_title("Performance Heatmap")

plt.show()

The background settings affect the figure and axes, while the heatmap itself uses its own color scale.

Create a Transparent Background

If you’re placing a Seaborn chart over another design, you may want the background to be transparent.

Matplotlib’s savefig() supports this:

import matplotlib.pyplot as plt
import seaborn as sns

x = [1, 2, 3, 4, 5]
y = [10, 15, 12, 20, 25]

figure, axis = plt.subplots()

sns.lineplot(
    x=x,
    y=y,
    ax=axis
)

figure.savefig(
    "transparent_chart.png",
    transparent=True,
    dpi=300,
    bbox_inches="tight"
)

plt.close(figure)

This can be useful when creating charts for websites, presentations, marketing materials, or other graphic designs.

Set a Custom Seaborn Style

Seaborn also provides built-in themes that influence the overall appearance of plots.

For example:

import seaborn as sns

sns.set_theme(style="whitegrid")

Other commonly used styles include:

sns.set_theme(style="white")
sns.set_theme(style="dark")
sns.set_theme(style="whitegrid")
sns.set_theme(style="darkgrid")
sns.set_theme(style="ticks")

You can then override the background color:

import matplotlib.pyplot as plt
import seaborn as sns

sns.set_theme(style="whitegrid")

sns.set(
    rc={
        "axes.facecolor": "#F4F8FB",
        "figure.facecolor": "#FFFFFF"
    }
)

x = [1, 2, 3, 4, 5]
y = [10, 15, 12, 20, 25]

sns.lineplot(x=x, y=y)

plt.show()

This combination gives you the benefits of Seaborn’s built-in styling while allowing you to customize the background.

Customize the Background for a Professional Dashboard

For dashboards, simply changing the background color isn’t always enough. You may also want to adjust the grid, borders, and text.

For example:

import matplotlib.pyplot as plt
import seaborn as sns

sns.set_theme(style="whitegrid")

x = [1, 2, 3, 4, 5, 6]
y = [120, 145, 135, 180, 210, 240]

figure, axis = plt.subplots(figsize=(10, 6))

figure.patch.set_facecolor("#F4F6F8")
axis.set_facecolor("#FFFFFF")

sns.lineplot(
    x=x,
    y=y,
    marker="o",
    linewidth=2,
    ax=axis
)

axis.set_title("Monthly Revenue")
axis.set_xlabel("Month")
axis.set_ylabel("Revenue")

sns.despine(ax=axis)

plt.tight_layout()
plt.show()

This approach is more suitable for business analytics because the chart separates the plotting area from the surrounding dashboard background.

Which Method Should You Use?

There are three particularly useful approaches.

MethodBest use
sns.set(rc=...)Applying a global Seaborn background style
axis.set_facecolor()Customizing one specific plot
figure.patch.set_facecolor()Customizing the entire figure

If you’re creating a single chart, using axis.set_facecolor() and figure.patch.set_facecolor() gives you clear and explicit control.

If you’re creating many charts with the same visual style, sns.set() or sns.set_theme() can be more convenient.

Common Problems When Changing Seaborn Background Colors

The background doesn’t change

Make sure you’re changing the correct component.

For the plotting area:

axis.set_facecolor("lightblue")

For the entire figure:

figure.patch.set_facecolor("lightgreen")

Seaborn resets your customization

If you call sns.set_theme() after manually configuring Seaborn or Matplotlib settings, some style settings may be overwritten.

A safer pattern is to establish the Seaborn theme first and then apply your custom settings:

sns.set_theme(style="whitegrid")

sns.set(
    rc={
        "axes.facecolor": "#F0F0F0",
        "figure.facecolor": "#FFFFFF"
    }
)

The chart looks too busy

A very strong background can compete with the data.

For analytical charts, subtle neutral colors often work better than extremely bright backgrounds. The primary goal should be keeping the data, labels, and annotations easy to read.

A Reusable Function for Seaborn Background Colors

If you frequently create charts with the same design, you can turn your styling into a function:

import matplotlib.pyplot as plt
import seaborn as sns


def set_chart_background(
    axis,
    axes_color="#F5F7FA",
    figure_color="#FFFFFF"
):
    figure = axis.figure

    axis.set_facecolor(axes_color)
    figure.patch.set_facecolor(figure_color)


x = [1, 2, 3, 4, 5]
y = [10, 15, 12, 20, 25]

figure, axis = plt.subplots(figsize=(8, 5))

sns.lineplot(
    x=x,
    y=y,
    marker="o",
    ax=axis
)

set_chart_background(
    axis,
    axes_color="#F5F7FA",
    figure_color="#FFFFFF"
)

axis.set_title("Example Trend")

plt.show()

This is especially useful in reporting systems where every chart needs to follow the same visual guidelines.

Final Example: A Clean Customized Seaborn Chart

Here is a complete example that combines several techniques:

import matplotlib.pyplot as plt
import seaborn as sns

sns.set_theme(style="whitegrid")

months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
sales = [120, 150, 140, 180, 210, 240]

figure, axis = plt.subplots(figsize=(10, 6))

axis.set_facecolor("#F7F9FC")
figure.patch.set_facecolor("#E9EEF5")

sns.lineplot(
    x=months,
    y=sales,
    marker="o",
    linewidth=2.5,
    ax=axis
)

axis.set_title("Monthly Sales Trend", fontsize=16)
axis.set_xlabel("Month")
axis.set_ylabel("Sales")

sns.despine(ax=axis)

figure.tight_layout()

plt.show()

This pattern gives you direct control over the plot background, figure background, dimensions, labels, and overall presentation.

Conclusion

Changing the background color of a Seaborn plot is easy once you understand the difference between the figure and axes.

For a global Seaborn configuration, you can use:

sns.set(
    rc={
        "axes.facecolor": "lightblue",
        "figure.facecolor": "lightgreen"
    }
)

For more precise control over an individual chart, use:

axis.set_facecolor("#F5F7FA")
figure.patch.set_facecolor("#FFFFFF")

Using HEX colors gives you virtually unlimited customization, while Seaborn’s themes such as whitegrid, darkgrid, and ticks provide a useful starting point.

For production-quality data visualizations, don’t choose a background color simply because it looks attractive. Consider contrast, readability, accessibility, branding, and where the chart will ultimately be displayed. A subtle background that keeps attention on the data is usually the most effective choice.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

two + 15 =