-
Notifications
You must be signed in to change notification settings - Fork 21
/
00-explore.py
39 lines (30 loc) · 947 Bytes
/
00-explore.py
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
import matplotlib.pyplot as plt
import numpy as np
last_ev = None
def event_printer(event):
"""Helper function for exploring events.
Prints all public attributes +
"""
# capture the last event
global last_ev
last_ev = event
for k, v in sorted(vars(event).items()):
print(f'{k}: {v!r}')
print('-'*25)
th = np.linspace(0, 2*np.pi, 64)
fig, ax = plt.subplots()
# the `picker=5` kwarg turn on pick-events for this artist
ax.plot(th, np.sin(th), 'o-', picker=5)
cid = fig.canvas.mpl_connect('button_press_event', event_printer)
plt.show()
# fig.canvas.mpl_disconnect(cid)
# EXERCISE (10 - 15 minutes)
#
# play around with events interactively
#
# - Try all 'active' events
# ['button_press_event', 'button_release_event', 'scroll_event',
# 'key_press_event', 'key_release_event', 'pick_event']
# - tweak the print line
# - remove a callback
# - add more than one callback to the canvas