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