- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change axes background color in Matplotlib?
To change the axes background color, we can use set_facecolor() method.
Steps
Set the figure size and adjust the padding between and around the subplots.
Get the current axes using gca() method.
Set the facecolor of the axes.
Create x and y data points using numpy.
Plot x and y data points using plot() method.
To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True ax = plt.gca() ax.set_facecolor("orange") x = np.linspace(-2, 2, 10) y = np.exp(-x) plt.plot(x, y, color='red') plt.show()
Output
- Related Articles
- Change the default background color for Matplotlib plots
- How to change JFrame background color in Java
- How to change the background color using jQuery?
- Change x axes scale in matplotlib
- How to change JLabel background and foreground color in Java?
- How to change a button background color using Swift?
- How to change header background color of a table in Java
- How to change the Background Color of Text in C# Console
- How to change the background color of the font in PowerShell?
- How to change the background color of a Treeview in Tkinter?
- How to change background color of TableView items on iOS?
- How to change the background color of the options menu in Android?
- How to animate a change in background color using jQuery on mouseover?
- How to change the background color of legend in base R plot?
- How to change the background color of ListView items on Android?

Advertisements