Registers a function to be run when a key is pressed in a Matplotlib visualizer.
Parameters
key — str, required
The key to listen for. The string must be one character; other strings, or strings not corresponding to a single key, will be ignored.
fn — func(model, event), required
A function to run when
key
is pressed in the Matplotlib visualization.model
is the model object, andevent
is the Matplotlib event object.
charwick
Feb 03, 2021 at 21:31When modifying the visualization after a keypress, always access the figure through
event.canvas.figure
and not throughmodel.visual.fig
. The former will correctly route the event to the currently open figure, whereas the latter will route the event to the figure corresponding to the currently active model, even if the key was pressed in the window of a terminated model.