How to Set Plot Background Color in Matplotlib?
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.
- 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
Example 2 : Setting background color to yellow
Example 3: Setting background color to violet
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 2: Setting plot color using html color codes
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course