

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 set local rcParams or rcParams for one figure in matplotlib?
To set local rcParams or rcParams for one figure in matplotlib, we can take the following steps −
Steps
Set the figure size and adjust the padding between and around the subplots.
Initialize a variable N to store the number of sample data.
Create x and y data points using numpy.
Return a context manager for temporarily changing rcParams.
Add a subplot to the current figure, at index 1.
Plot the x and y data points, using plot() method.
Add a subplot to the current figure, at index 2.
Plot the x and y data points, using plot() method.
To display the figure, use show() method.
Example
import pandas as pd import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True N = 10 x = np.random.rand(N) y = np.random.rand(N) with plt.rc_context({"axes.grid": True, "grid.linewidth": 0.75, "lines.linestyle": 'dashed'}): plt.subplot(121) plt.plot(x, y) plt.subplot(122) plt.plot(x, y) plt.show()
Output
It will produce the following output −
- Related Questions & Answers
- How to set the current figure in Matplotlib?
- How to show multiple images in one figure in Matplotlib?
- How to set the margins of a Matplotlib figure?
- How to combine several matplotlib axes subplots into one figure?
- How to display multiple images in one figure correctly in matplotlib?
- How to set the matplotlib figure default size in ipython notebook?
- Change figure size and figure format in Matplotlib
- What is the preferred way to set Matplotlib figure/axes properties?
- How to retrieve colorbar instance from figure in Matplotlib?
- How to change the default path for "save the figure" in Matplotlib?
- How to convert Matplotlib figure to PIL Image object?
- How to set "step" on axis X in my figure in Matplotlib Python 2.6.6?
- How to set the xticklabels for date in matplotlib?
- How to retrieve XY data from a Matplotlib figure?
- How to position and align a Matplotlib figure legend?
Advertisements