- 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
Text box with line wrapping in Matplotlib
Matplotlib can wrap text automatically, but if it's too long, the text will be displayed slightly outside of the boundaries of the axis anyways.
Steps
Create a new figure, or activate an existing figure, using figure().
Set the axis properties using plt.axis() method.
Make a variable input_text to store the string.
Add text to figure, using plt.text() method where style='oblique', ha='center', va='top', ...etc.
To show the figure use plt.show() method.
Example
import matplotlib.pyplot as plt fig = plt.figure() plt.axis([0, 10, 0, 10]) input_text = 'Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy.' plt.text(5, 5, input_text, fontsize=10, style='oblique', ha='center', va='top', wrap=True, rotation=-30) plt.show()
Output
- Related Articles
- Automatically position text box in Matplotlib
- Python Text Wrapping and Filling
- Textwrap - Text wrapping and filling in Python
- Disable text wrapping inside an element using CSS
- Legend with vertical line in matplotlib
- Line plot with arrows in Matplotlib
- Wrapping long Y labels in Matplotlib tight layout using setp
- Adding default search text to search box in HTML with JavaScript?
- How to upload a file in Selenium with no text box?
- Box plot with min, max, average and standard deviation in Matplotlib
- Text in Transparent Box using CSS3
- How to annotate a heatmap with text in Matplotlib?
- Avoid wrapping flex items with CSS
- How to annotate several points with one text in Matplotlib?
- How to key in values in input text box with Javascript executor in Selenium with python?

Advertisements