3
3
Demo Text Rotation Mode
4
4
=======================
5
5
6
+ The axes method text takes an argument rotation_mode that controls the
7
+ alignment and rotation of the text. If rotation_mode is None or "default" the
8
+ text will first be rotated and then aligned according to the horizontal and
9
+ vertical alignments (ha and va in the example). If rotation_mode is "anchor"
10
+ the text is aligned before rotation.
11
+
6
12
"""
13
+ import matplotlib
7
14
from mpl_toolkits .axes_grid1 .axes_grid import ImageGrid
8
15
9
16
@@ -19,18 +26,23 @@ def test_rotation_mode(fig, mode, subplot_location):
19
26
for ha , ax in zip (ha_list , grid .axes_row [- 1 ]):
20
27
ax .axis ["bottom" ].label .set_text (ha )
21
28
29
+ # create a grid of axes to display text on.
22
30
grid .axes_row [0 ][1 ].set_title (mode , size = "large" )
23
31
24
32
for va , ax in zip (va_list , grid .axes_column [0 ]):
25
33
ax .axis ["left" ].label .set_text (va )
26
34
35
+ # use a different horizontal and vertical alignment for the text in each
36
+ # axes.
27
37
i = 0
28
38
for va in va_list :
29
39
for ha in ha_list :
30
40
ax = grid [i ]
31
41
for axis in ax .axis .values ():
32
42
axis .toggle (ticks = False , ticklabels = False )
33
43
44
+ # add text to the axes. Set the rotation_mode, horizontal
45
+ # alignment (ha) and vertical alignment (va).
34
46
ax .text (0.5 , 0.5 , "Tpg" ,
35
47
size = "large" , rotation = 40 ,
36
48
bbox = dict (boxstyle = "square,pad=0." ,
@@ -48,3 +60,16 @@ def test_rotation_mode(fig, mode, subplot_location):
48
60
test_rotation_mode (fig , "default" , 121 )
49
61
test_rotation_mode (fig , "anchor" , 122 )
50
62
plt .show ()
63
+
64
+
65
+ #############################################################################
66
+ #
67
+ # ------------
68
+ #
69
+ # References
70
+ # """"""""""
71
+ #
72
+ # The use of the following method is shown in this example:
73
+
74
+
75
+ matplotlib .axes .Axes .text
0 commit comments