Bind function func to event s.
One of the following events ids:
The callback function to be executed, which must have the signature:
def func(event: Event) -> Any
For the location events (button and key press/release), if the mouse is over the Axes, the inaxes attribute of the event will be set to the Axes the event occurs is over, and additionally, the variables xdata and ydata attributes will be set to the mouse location in data coordinates. See KeyEvent and MouseEvent for more info.
Note
If func is a method, this only stores a weak reference to the method. Thus, the figure does not influence the lifetime of the associated object. Usually, you want to make sure that the object is kept alive throughout the lifetime of the figure by holding a reference to it.
A connection id that can be used with FigureCanvasBase.mpl_disconnect.
Note
This is the pyplot wrapper for FigureCanvasBase.mpl_connect.
def on_press(event):
print('you pressed', event.button, event.xdata, event.ydata)
cid = canvas.mpl_connect('button_press_event', on_press)
matplotlib.pyplot.connect
© 2012–2023 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.connect.html