Skip to content

Commit ca2ac85

Browse files
authored
Merge pull request #8228 from dstansby/alignment-example
MEP12 text alignment example
2 parents dab867b + ceeda36 commit ca2ac85

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

examples/pylab_examples/alignment_test.py renamed to examples/text_labels_and_annotations/text_alignment.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
"""
2+
===================
3+
Precise text layout
4+
===================
5+
26
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.
59
"""
610

711
import matplotlib.pyplot as plt
812
from matplotlib.lines import Line2D
913
from matplotlib.patches import Rectangle
1014

11-
# build a rectangle in axes coords
15+
# Build a rectangle in axes coords
1216
left, width = .25, .5
1317
bottom, height = .25, .5
1418
right = left + width
1519
top = bottom + height
1620
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)
2022
p.set_transform(ax.transAxes)
2123
p.set_clip_on(False)
2224
ax.add_patch(p)
@@ -47,24 +49,24 @@
4749
verticalalignment='top',
4850
transform=ax.transAxes)
4951

50-
ax.text(left, 0.5*(bottom + top), 'right center',
52+
ax.text(left, 0.5 * (bottom + top), 'right center',
5153
horizontalalignment='right',
5254
verticalalignment='center',
5355
rotation='vertical',
5456
transform=ax.transAxes)
5557

56-
ax.text(left, 0.5*(bottom + top), 'left center',
58+
ax.text(left, 0.5 * (bottom + top), 'left center',
5759
horizontalalignment='left',
5860
verticalalignment='center',
5961
rotation='vertical',
6062
transform=ax.transAxes)
6163

62-
ax.text(0.5*(left + right), 0.5*(bottom + top), 'middle',
64+
ax.text(0.5 * (left + right), 0.5 * (bottom + top), 'middle',
6365
horizontalalignment='center',
6466
verticalalignment='center',
6567
transform=ax.transAxes)
6668

67-
ax.text(right, 0.5*(bottom + top), 'centered',
69+
ax.text(right, 0.5 * (bottom + top), 'centered',
6870
horizontalalignment='center',
6971
verticalalignment='center',
7072
rotation='vertical',

0 commit comments

Comments
 (0)