- 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 the unit length of an axis in Matplotlib?
To set the unit length of an axis in Matplotlib, we can use xlim or ylim with scale factor of the axes, i.e., of unit length times.
steps
Set the figure size and adjust the padding between and around the subplots.
Create x and y data points using numpy.
Plot the x and y data points using plot() method.
Get the x and y axes, limit range.
Use xlim and ylim methods to set the unit length scale.
To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(1, 10, 100) y = np.log(x) plt.plot(x, y) axis_scale = 2 xmin, xmax = plt.xlim() ymin, ymax = plt.ylim() plt.xlim(xmin * axis_scale, xmax * axis_scale) plt.ylim(ymin * axis_scale, ymax * axis_scale) plt.show()
Output
- Related Articles
- How can I get the length of a single unit on an axis in Matplotlib?
- How to set the value of the axis multiplier in matplotlib?
- How to set the font size of Matplotlib axis Legend?
- How to set X-axis values in Matplotlib Python?
- How to set my xlabel at the end of X-axis in Matplotlib?
- How to set axis ticks in multiples of pi in Python Matplotlib?
- Changing the color of an axis in Matplotlib
- How to draw a line outside of an axis in Matplotlib?
- How to set the range of Y-axis for a Seaborn boxplot using Matplotlib?
- How to change the range of the X-axis and Y-axis in Matplotlib?
- How to set "step" on axis X in my figure in Matplotlib Python 2.6.6?
- How to customize the X-axis in Matplotlib?
- How to Adjust the Position of Axis Labels in Matplotlib?
- How to enforce axis range in Matplotlib?
- How to annotate a range of the X-axis in Matplotlib?

Advertisements