FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/examples/units/artist_tests.py at master · staticfloat/matplotlib · GitHub
staticfloat
matplotlib
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
examples
/
units
/
artist_tests.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (45 loc) · 1.5 KB
Breadcrumbs
matplotlib
/
examples
/
units
/
artist_tests.py
Copy path
File metadata and controls
55 lines (45 loc) · 1.5 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
"""
Test unit support with each of the matplotlib primitive artist types
The axes handles unit conversions and the artists keep a pointer to
their axes parent, so you must init the artists with the axes instance
if you want to initialize them with unit data, or else they will not
know how to convert the units to scalars
"""
import
random
import
matplotlib
.
lines
as
lines
import
matplotlib
.
patches
as
patches
import
matplotlib
.
text
as
text
import
matplotlib
.
collections
as
collections
import
matplotlib
.
units
as
units
from
basic_units
import
cm
,
inch
import
numpy
as
np
from
matplotlib
.
pyplot
import
figure
,
show
fig
=
figure
()
ax
=
fig
.
add_subplot
(
111
)
ax
.
xaxis
.
set_units
(
cm
)
ax
.
yaxis
.
set_units
(
cm
)
if
0
:
# test a line collection
# Not supported at present.
verts
=
[]
for
i
in
range
(
10
):
# a random line segment in inches
verts
.
append
(
zip
(
*
inch
*
10
*
np
.
random
.
rand
(
2
,
random
.
randint
(
2
,
15
))))
lc
=
collections
.
LineCollection
(
verts
,
axes
=
ax
)
ax
.
add_collection
(
lc
)
# test a plain-ol-line
line
=
lines
.
Line2D
([
0
*
cm
,
1.5
*
cm
], [
0
*
cm
,
2.5
*
cm
],
lw
=
2
,
color
=
'black'
,
axes
=
ax
)
ax
.
add_line
(
line
)
if
0
:
# test a patch
# Not supported at present.
rect
=
patches
.
Rectangle
( (
1
*
cm
,
1
*
cm
),
width
=
5
*
cm
,
height
=
2
*
cm
,
alpha
=
0.2
,
axes
=
ax
)
ax
.
add_patch
(
rect
)
t
=
text
.
Text
(
3
*
cm
,
2.5
*
cm
,
'text label'
,
ha
=
'left'
,
va
=
'bottom'
,
axes
=
ax
)
ax
.
add_artist
(
t
)
ax
.
set_xlim
(
-
1
*
cm
,
10
*
cm
)
ax
.
set_ylim
(
-
1
*
cm
,
10
*
cm
)
#ax.xaxis.set_units(inch)
ax
.
grid
(
True
)
ax
.
set_title
(
"Artists with units"
)
show
()
Back
|
FazBrowse Home
|
New Git URL