PointBrowser
:
"""
Click on a point to select and highlight it -- the data that
generated the point will be shown in the lower Axes. Use the 'n'
and 'p' keys to browse through the next and previous points
"""
def
__init__
(
self
):
self
.
lastind
=
0
self
.
text
=
(
0.05
,
0.95
,
'selected: none'
,
transform
=
,
va
=
'top'
)
self
.
selected
,
=
([
[
0
]],
[
[
0
]],
'o'
,
ms
=
12
,
alpha
=
0.4
,
color
=
'yellow'
,
visible
=
False
)
def
on_press
(
self
,
event
):
if
self
.
lastind
is
None
:
return
if
event
.
key
not
in
(
'n'
,
'p'
):
return
if
event
.
key
==
'n'
:
inc
=
1
else
:
inc
=
-
1
self
.
lastind
+=
inc
self
.
lastind
=
(
self
.
lastind
,
0
,
len
(
)
-
1
)
self
.
update
()
def
on_pick
(
self
,
event
):
if
event
.
artist
!=
:
return
True
N
=
len
(
event
.
ind
)
if
not
N
:
return
True
x
=
event
.
mouseevent
.
xdata
y
=
event
.
mouseevent
.
ydata
distances
=
(
x
-
[
event
.
ind
],
y
-
[
event
.
ind
])
indmin
=
distances
.
argmin
()
dataind
=
event
.
ind
[
indmin
]
self
.
lastind
=
dataind
self
.
update
()
def
update
(
self
):
if
self
.
lastind
is
None
:
return
dataind
=
self
.
lastind
()
(
[
dataind
])
(
0.05
,
0.9
,
f
'mu=
{
[
dataind
]
:
1.3f
}
\n
sigma=
{
[
dataind
]
:
1.3f
}
'
,
transform
=
,
va
=
'top'
)
(
-
0.5
,
1.5
)
self
.
selected
.
set_visible
(
True
)
self
.
selected
.
set_data
([
[
dataind
]],
[
[
dataind
]])
self
.
text
.
set_text
(
'selected:
%d
'
%
dataind
)
()
if
__name__
==
'__main__'
:
import
matplotlib.pyplot
as
plt
(
19680801
)
=
(
100
,
200
)
=
(
,
axis
=
1
)
=
(
,
axis
=
1
)
,
(
,
)
=
(
2
,
1
)
(
'click on point to plot time series'
)
,
=
(
,
,
'o'
,
picker
=
True
,
pickradius
=
5
)
browser
=
PointBrowser
()
(
'pick_event'
,
browser
.
on_pick
)
(
'key_press_event'
,
browser
.
on_press
)
()