Menu

[r150]: / trunk / htdocs / examples / alignment_test.py  Maximize  Restore  History

Download this file

87 lines (73 with data), 2.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
You can precisely layout text in data or axes (0,1) coordinates. This
example shows you some of the alignment and rotation specifications to
layout text
"""
from matplotlib.matlab import *
from matplotlib.lines import Line2D
from matplotlib.patches import Rectangle
from matplotlib.transforms import Transform
# build a rectangle in axes coords
left, width = .25, .5
bottom, height = .25, .5
right = left + width
top = bottom + height
ax = gca()
p = Rectangle(ax.dpi, ax.bbox,
(left, bottom), width, height,
fill=False,
transx=ax.xaxis.transAxis,
transy=ax.yaxis.transAxis)
p.set_clip_on(False)
ax.add_patch(p)
ax.text(left, bottom, 'left top',
horizontalalignment='left',
verticalalignment='top',
transx=ax.xaxis.transAxis,
transy=ax.yaxis.transAxis)
ax.text(left, bottom, 'left bottom',
horizontalalignment='left',
verticalalignment='bottom',
transx=ax.xaxis.transAxis,
transy=ax.yaxis.transAxis)
ax.text(right, top, 'right bottom',
horizontalalignment='right',
verticalalignment='bottom',
transx=ax.xaxis.transAxis,
transy=ax.yaxis.transAxis)
ax.text(right, top, 'right top',
horizontalalignment='right',
verticalalignment='top',
transx=ax.xaxis.transAxis,
transy=ax.yaxis.transAxis)
ax.text(right, bottom, 'center top',
horizontalalignment='center',
verticalalignment='top',
transx=ax.xaxis.transAxis,
transy=ax.yaxis.transAxis)
ax.text(left, 0.5*(bottom+top), 'right center',
horizontalalignment='right',
verticalalignment='center',
rotation='vertical',
transx=ax.xaxis.transAxis,
transy=ax.yaxis.transAxis)
ax.text(left, 0.5*(bottom+top), 'leftcenter',
horizontalalignment='left',
verticalalignment='center',
rotation='vertical',
transx=ax.xaxis.transAxis,
transy=ax.yaxis.transAxis)
ax.text(0.5*(left+right), 0.5*(bottom+top), 'middle',
horizontalalignment='center',
verticalalignment='center',
transx=ax.xaxis.transAxis,
transy=ax.yaxis.transAxis)
ax.text(right, 0.5*(bottom+top), 'centered',
horizontalalignment='center',
verticalalignment='center',
rotation='vertical',
transx=ax.xaxis.transAxis,
transy=ax.yaxis.transAxis)
axis('off')
#savefig('alignment_test', dpi=300)
show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.