|
1 | 1 | """ |
| 2 | +=================== |
| 3 | +Precise text layout |
| 4 | +=================== |
| 5 | +
|
2 | 6 | You can precisely layout text in data or axes (0,1) coordinates. This |
3 | | -example shows you some of the alignment and rotation specifications to |
4 | | -layout text |
| 7 | +example shows you some of the alignment and rotation specifications for text |
| 8 | +layout. |
5 | 9 | """ |
6 | 10 |
|
7 | 11 | import matplotlib.pyplot as plt |
8 | 12 | from matplotlib.lines import Line2D |
9 | 13 | from matplotlib.patches import Rectangle |
10 | 14 |
|
11 | | -# build a rectangle in axes coords |
| 15 | +# Build a rectangle in axes coords |
12 | 16 | left, width = .25, .5 |
13 | 17 | bottom, height = .25, .5 |
14 | 18 | right = left + width |
15 | 19 | top = bottom + height |
16 | 20 | ax = plt.gca() |
17 | | -p = plt.Rectangle((left, bottom), width, height, |
18 | | - fill=False, |
19 | | - ) |
| 21 | +p = plt.Rectangle((left, bottom), width, height, fill=False) |
20 | 22 | p.set_transform(ax.transAxes) |
21 | 23 | p.set_clip_on(False) |
22 | 24 | ax.add_patch(p) |
|
47 | 49 | verticalalignment='top', |
48 | 50 | transform=ax.transAxes) |
49 | 51 |
|
50 | | -ax.text(left, 0.5*(bottom + top), 'right center', |
| 52 | +ax.text(left, 0.5 * (bottom + top), 'right center', |
51 | 53 | horizontalalignment='right', |
52 | 54 | verticalalignment='center', |
53 | 55 | rotation='vertical', |
54 | 56 | transform=ax.transAxes) |
55 | 57 |
|
56 | | -ax.text(left, 0.5*(bottom + top), 'left center', |
| 58 | +ax.text(left, 0.5 * (bottom + top), 'left center', |
57 | 59 | horizontalalignment='left', |
58 | 60 | verticalalignment='center', |
59 | 61 | rotation='vertical', |
60 | 62 | transform=ax.transAxes) |
61 | 63 |
|
62 | | -ax.text(0.5*(left + right), 0.5*(bottom + top), 'middle', |
| 64 | +ax.text(0.5 * (left + right), 0.5 * (bottom + top), 'middle', |
63 | 65 | horizontalalignment='center', |
64 | 66 | verticalalignment='center', |
65 | 67 | transform=ax.transAxes) |
66 | 68 |
|
67 | | -ax.text(right, 0.5*(bottom + top), 'centered', |
| 69 | +ax.text(right, 0.5 * (bottom + top), 'centered', |
68 | 70 | horizontalalignment='center', |
69 | 71 | verticalalignment='center', |
70 | 72 | rotation='vertical', |
|
0 commit comments