- 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
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 Articles
- 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 set the matplotlib figure default size in ipython notebook?
- How to display multiple images in one figure correctly in matplotlib?
- How to combine several matplotlib axes subplots into one figure?
- How to set the xticklabels for date in matplotlib?
- How to set "step" on axis X in my figure in Matplotlib Python 2.6.6?
- How to change the default path for "save the figure" in Matplotlib?
- How to set label for an already plotted line in Matplotlib?
- How to set same scale for subplots in Python using Matplotlib?
- What is the preferred way to set Matplotlib figure/axes properties?
- How to set timeout to pyplot.show() in Matplotlib?
- How to retrieve colorbar instance from figure in Matplotlib?
- How to pick a new color for each plotted line within a figure in matplotlib?

Advertisements