October 2018
Beginner to intermediate
676 pages
18h 30m
English
Here is the code for plotting the sin and cos functions with a legend and title, and capturing keyboard events and associated callback functions to respond to the keyboard events:
def press(event): global prst prst = time() print('press', event.key)
def release(event): relt = time() ht = relt - prst print('hold time:',round(ht,2)) if event.key == 'x': visible = lg.get_visible() lg.set_visible(not visible) tm = 'hold time: ' + str(round(ht, 2)) t = plt.text(np.random.randint(1,4), np.random.randint(-3,4), tm) plt.setp(t, color='r', size=15, weight='bold') ax.add_artist(t) fig.canvas.draw()
Read now
Unlock full access