FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/examples/misc/transoffset.py at unpyplot · a52/matplotlib · GitHub
a52
matplotlib
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
examples
/
misc
/
transoffset.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
58 lines (45 loc) · 1.76 KB
Breadcrumbs
matplotlib
/
examples
/
misc
/
transoffset.py
Copy path
File metadata and controls
58 lines (45 loc) · 1.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
'''
===========
Transoffset
===========
This illustrates the use of transforms.offset_copy to
make a transform that positions a drawing element such as
a text string at a specified offset in screen coordinates
(dots or inches) relative to a location given in any
coordinates.
Every Artist--the mpl class from which classes such as
Text and Line are derived--has a transform that can be
set when the Artist is created, such as by the corresponding
pyplot command. By default this is usually the Axes.transData
transform, going from data units to screen dots. We can
use the offset_copy function to make a modified copy of
this transform, where the modification consists of an
offset.
'''
import
matplotlib
.
pyplot
as
plt
import
matplotlib
.
transforms
as
mtransforms
import
numpy
as
np
xs
=
np
.
arange
(
7
)
ys
=
xs
**
2
fig
=
plt
.
figure
(
figsize
=
(
5
,
10
))
ax
=
plt
.
subplot
(
2
,
1
,
1
)
# If we want the same offset for each text instance,
# we only need to make one transform. To get the
# transform argument to offset_copy, we need to make the axes
# first; the subplot command above is one way to do this.
trans_offset
=
mtransforms
.
offset_copy
(
ax
.
transData
,
fig
=
fig
,
x
=
0.05
,
y
=
0.10
,
units
=
'inches'
)
for
x
,
y
in
zip
(
xs
,
ys
):
plt
.
plot
(
x
,
y
,
'ro'
)
plt
.
text
(
x
,
y
,
'%d, %d'
%
(
int
(
x
),
int
(
y
)),
transform
=
trans_offset
)
# offset_copy works for polar plots also.
ax
=
plt
.
subplot
(
2
,
1
,
2
,
projection
=
'polar'
)
trans_offset
=
mtransforms
.
offset_copy
(
ax
.
transData
,
fig
=
fig
,
y
=
6
,
units
=
'dots'
)
for
x
,
y
in
zip
(
xs
,
ys
):
plt
.
polar
(
x
,
y
,
'ro'
)
plt
.
text
(
x
,
y
,
'%d, %d'
%
(
int
(
x
),
int
(
y
)),
transform
=
trans_offset
,
horizontalalignment
=
'center'
,
verticalalignment
=
'bottom'
)
plt
.
show
()
Back
|
FazBrowse Home
|
New Git URL