- 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
What is the preferred way to set Matplotlib figure/axes properties?
To set the properties of a plot, we can get the current axis of the plot. After that, we can perform several set_* methods to set the properties of the plot.
Steps
Create a figure and a set of subplots using subplots() method with figsize=(5, 5).
Create x and y data points using numpy.
Plot x and y using plot() method.
Set the title and labels (for X and Y axis) using set_xlabel() and set_ylabel() methods.
To display the figure, use show() method.
Example
import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() x = np.linspace(-1, 1, 10) y = np.exp(x) ax.plot(x, y, c='red') ax.set_title('y=exp(x)') ax.set_xlabel('x') ax.set_ylabel('y') plt.show()
Output
- Related Articles
- What is the preferred way to concatenate a string in Python?
- What is the difference between drawing plots using plot, axes or figure in matplotlib?
- How to combine several matplotlib axes subplots into one figure?
- What exactly is a Matplotlib axes object?
- How to set the current 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 remove a frame without removing the axes tick labels from a Matplotlib figure in Python?
- How to switch axes in Matplotlib?
- What is the correct way to replace matplotlib tick labels with computed values?
- How to rotate a simple matplotlib Axes?
- How to make axes transparent in Matplotlib?
- What is the cost of preferred stock?
- How should I pass a matplotlib object through a function; as Axis, Axes or Figure?
- Which is the recommended way to plot – matplotlib or pylab?

Advertisements