Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ada3f9a

Browse files
committed
Added what's new entry and example for autowrapping text
1 parent abec281 commit ada3f9a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

doc/users/whats_new/autowrap_text.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Auto-wrapping Text
2+
------------------
3+
Added the keyword argument "wrap" to Text, which automatically breaks long lines of text when being drawn.
4+
Works for any rotated text, different modes of alignment, and for text that are either labels or titles.
5+
6+
Example:
7+
plt.text(1, 1, "This is a really long string that should be wrapped so that it does not go outside the figure.", wrap=True)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Auto-wrapping text demo.
3+
"""
4+
import matplotlib.pyplot as plt
5+
6+
fig = plt.figure()
7+
plt.axis([0, 10, 0, 10])
8+
t = "This is a really long string that I'd rather have wrapped so that it"\
9+
" doesn't go outside of the figure, but if it's long enough it will go"\
10+
" off the top or bottom!"
11+
plt.text(4, 1, t, ha='left', rotation=15, wrap=True)
12+
plt.text(6, 5, t, ha='left', rotation=15, wrap=True)
13+
plt.text(5, 5, t, ha='right', rotation=-15, wrap=True)
14+
plt.text(5, 10, t, fontsize=18, style='oblique', ha='center',
15+
va='top', wrap=True)
16+
plt.text(3, 4, t, family='serif', style='italic', ha='right', wrap=True)
17+
plt.text(-1, 0, t, ha='left', rotation=-15, wrap=True)
18+
19+
plt.show()

0 commit comments

Comments
 (0)