FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/examples/dynamic_collection.py at transforms · tecki/matplotlib · GitHub
tecki
matplotlib
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
examples
/
dynamic_collection.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (42 loc) · 1.17 KB
Breadcrumbs
matplotlib
/
examples
/
dynamic_collection.py
Copy path
File metadata and controls
48 lines (42 loc) · 1.17 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
import
random
from
matplotlib
.
collections
import
RegularPolyCollection
import
matplotlib
.
cm
as
cm
from
matplotlib
.
pyplot
import
figure
,
show
from
numpy
.
random
import
rand
fig
=
figure
()
ax
=
fig
.
add_subplot
(
111
,
xlim
=
(
0
,
1
),
ylim
=
(
0
,
1
),
autoscale_on
=
False
)
ax
.
set_title
(
"Press 'a' to add a point, 'd' to delete one"
)
# a single point
offsets
=
[(
0.5
,
0.5
)]
facecolors
=
[
cm
.
jet
(
0.5
)]
collection
=
RegularPolyCollection
(
fig
.
dpi
,
numsides
=
5
,
# a pentagon
rotation
=
0
,
sizes
=
(
50
,),
facecolors
=
facecolors
,
edgecolors
=
'black'
,
linewidths
=
(
1
,),
offsets
=
offsets
,
transOffset
=
ax
.
transData
,
)
ax
.
add_collection
(
collection
)
def
onpress
(
event
):
"""
press 'a' to add a random point from the collection, 'd' to delete one
"""
if
event
.
key
==
'a'
:
x
,
y
=
rand
(
2
)
color
=
cm
.
jet
(
rand
())
offsets
.
append
((
x
,
y
))
facecolors
.
append
(
color
)
fig
.
canvas
.
draw
()
elif
event
.
key
==
'd'
:
N
=
len
(
offsets
)
if
N
>
0
:
ind
=
random
.
randint
(
0
,
N
-
1
)
offsets
.
pop
(
ind
)
facecolors
.
pop
(
ind
)
fig
.
canvas
.
draw
()
fig
.
canvas
.
mpl_connect
(
'key_press_event'
,
onpress
)
show
()
Back
|
FazBrowse Home
|
New Git URL