FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib.github.com/examples/widgets/rectangle_selector.py at master · Redwa/matplotlib.github.com · GitHub
Redwa
/
matplotlib.github.com
Public
forked from
matplotlib/matplotlib.github.com
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib.github.com
/
examples
/
widgets
/
rectangle_selector.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (42 loc) · 2.15 KB
Breadcrumbs
matplotlib.github.com
/
examples
/
widgets
/
rectangle_selector.py
Copy path
File metadata and controls
52 lines (42 loc) · 2.15 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
from
__future__
import
print_function
"""
Do a mouseclick somewhere, move the mouse to some destination, release
the button. This class gives click- and release-events and also draws
a line or a box from the click-point to the actual mouseposition
(within the same axes) until the button is released. Within the
method 'self.ignore()' it is checked wether the button from eventpress
and eventrelease are the same.
"""
from
matplotlib
.
widgets
import
RectangleSelector
import
numpy
as
np
import
matplotlib
.
pyplot
as
plt
def
line_select_callback
(
eclick
,
erelease
):
'eclick and erelease are the press and release events'
x1
,
y1
=
eclick
.
xdata
,
eclick
.
ydata
x2
,
y2
=
erelease
.
xdata
,
erelease
.
ydata
print
(
"(%3.2f, %3.2f) --> (%3.2f, %3.2f)"
%
(
x1
,
y1
,
x2
,
y2
))
print
(
" The button you used were: %s %s"
%
(
eclick
.
button
,
erelease
.
button
))
def
toggle_selector
(
event
):
print
(
' Key pressed.'
)
if
event
.
key
in
[
'Q'
,
'q'
]
and
toggle_selector
.
RS
.
active
:
print
(
' RectangleSelector deactivated.'
)
toggle_selector
.
RS
.
set_active
(
False
)
if
event
.
key
in
[
'A'
,
'a'
]
and
not
toggle_selector
.
RS
.
active
:
print
(
' RectangleSelector activated.'
)
toggle_selector
.
RS
.
set_active
(
True
)
fig
,
current_ax
=
plt
.
subplots
()
# make a new plotingrange
N
=
100000
# If N is large one can see
x
=
np
.
linspace
(
0.0
,
10.0
,
N
)
# improvement by use blitting!
plt
.
plot
(
x
,
+
np
.
sin
(
.2
*
np
.
pi
*
x
),
lw
=
3.5
,
c
=
'b'
,
alpha
=
.7
)
# plot something
plt
.
plot
(
x
,
+
np
.
cos
(
.2
*
np
.
pi
*
x
),
lw
=
3.5
,
c
=
'r'
,
alpha
=
.5
)
plt
.
plot
(
x
,
-
np
.
sin
(
.2
*
np
.
pi
*
x
),
lw
=
3.5
,
c
=
'g'
,
alpha
=
.3
)
print
(
"
\n
click --> release"
)
# drawtype is 'box' or 'line' or 'none'
toggle_selector
.
RS
=
RectangleSelector
(
current_ax
,
line_select_callback
,
drawtype
=
'box'
,
useblit
=
True
,
button
=
[
1
,
3
],
# don't use middle button
minspanx
=
5
,
minspany
=
5
,
spancoords
=
'pixels'
,
interactive
=
True
)
plt
.
connect
(
'key_press_event'
,
toggle_selector
)
plt
.
show
()
Back
|
FazBrowse Home
|
New Git URL