VOOZH about

URL: https://www.geeksforgeeks.org/data-visualization/how-to-set-plot-background-color-in-matplotlib/

⇱ How to Set Plot Background Color in Matplotlib? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Set Plot Background Color in Matplotlib?

Last Updated : 23 Jul, 2025

Prerequisites: 

From the below figure one can infer that a plot consists of X-axis, Y-axis, plot title and the axes. By default, the color of the plot is white. If we have to set the background color of the plot so that our plot looks beautiful, we have to make the axes object, by using axes() attribute after plotting the graph.

👁 Image

Approach:

  • Import module
  • Load or create data
  • Plot a regular graph
  • Create axes object
  • Set attribute set_facecolor() to the required color. This attribute accepts both name or color code of the color

Follow the given examples to understand better.

Example: Default color plot

Output:

👁 Image

Example 2 : Setting background color to yellow

Output:

👁 Image

Example 3: Setting background color to violet

Output:

👁 Image

Setting Outer and Inner color of plot

We can also set the color of the outer portion of the plot. To set both the color for plot background and for outer portion of the plot the only change we have to do in our code is that we have to add plt.figure(faceccolor='color') before plotting the graph.

Example 1:

Output:

👁 Image

Example 2: Setting plot color using html color codes

Output:

👁 Image

Comment