- 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 autosize text in matplotlib Python?
To autosize text in matplotlib, we can make a tight layout and rotate the ticks.
Steps
Set the figure size and adjust the padding between and around the subplots.
Plot data points of the range of 10.
Make a list of labels.
Put ticks and labels on the X-axis with 30 rotation.
To display the figure, use Show() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True plt.plot(range(10)) labels = [7 * repr(i) for i in range(10)] plt.xticks(range(10), labels, rotation=30) plt.show()
Output
It will produce the following output −
- Related Articles
- How to add AutoSize Input in React.js?
- How to refresh text in Matplotlib?
- How to animate text in Matplotlib?
- How to add bold annotated text in Matplotlib?
- How to annotate a heatmap with text in Matplotlib?
- How to add text inside a plot in Matplotlib?
- How to write text above the bars on a bar plot (Python Matplotlib)?
- How to curve text in a polar plot in matplotlib?
- How to put text at the corner of an equal aspect figure in Python/Matplotlib?
- How to add a text into a Rectangle in Matplotlib?
- How to annotate several points with one text in Matplotlib?
- How to import Matplotlib in Python?
- How to install matplotlib in Python?
- How to change fonts in matplotlib (python)?
- Automatically position text box in Matplotlib

Advertisements