- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Change the default background color for Matplotlib plots
To change the default background color for Matplotlib plots, we can take the following steps −
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Get the current axis.
- Add a subplot to the current figure, with nrows=1, ncols=2 and index=1.
- Plot random x and y data points using plots() method.
- Set the title of the subplot.
- Add a subplot to the current figure with nrows=1, ncols=2 and index=2.
- Get the current axis.
- Set the customize face color.
- Plot x and y data points using plot() method.
- Set the title of the plot.
- 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() print("Default face color is: ", ax.get_facecolor()) plt.subplot(121) plt.plot(np.random.rand(10), np.random.rand(10)) plt.title("With default face color") plt.subplot(122) ax = plt.gca() ax.set_facecolor("orange") plt.plot(np.random.rand(10), np.random.rand(10)) plt.title("With customize face color") plt.show()
Output
- Related Articles
- How to change axes background color in Matplotlib?
- How do you change the default font color for all text in Matplotlib?
- How to set default background color for JTextPane in Java?
- How to change the datetime tick label frequency for Matplotlib plots?
- Fixing color in scatter plots in Matplotlib
- How to change the background color using jQuery?
- Dynamically change the widget background color in Tkinter
- How to change the default path for "save the figure" in Matplotlib?
- Change the background color of a button with CSS
- How to change JFrame background color in Java
- Java Program to customize MenuBar and change the background color
- How to change the background color of the font in PowerShell?
- How to change a button background color using Swift?
- How to change the background color of ListView items on Android?
- How to change the Background Color of Text in C# Console

Advertisements