- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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.
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.
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()
It will produce the following output −
- 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 curve text in a polar plot in matplotlib?
- How to write text above the bars on a bar plot (Python Matplotlib)?
- How to add a text into a Rectangle in Matplotlib?
- How to annotate several points with one text in Matplotlib?
- How to put text at the corner of an equal aspect figure in Python/Matplotlib?
- Automatically position text box in Matplotlib
- Adjusting Text background transparency in Matplotlib
- Text alignment in a Matplotlib legend
- How to install matplotlib in Python?
- How to import Matplotlib in Python?