Bind function *func* to event *s*. Parameters ---------- s : str One of the following events ids: - 'button_press_event' - 'button_release_event' - 'draw_event' - 'key_press_event' - 'key_relea
(self, s, func)
| 2322 | return f'{default_basename}.{default_filetype}' |
| 2323 | |
| 2324 | def mpl_connect(self, s, func): |
| 2325 | """ |
| 2326 | Bind function *func* to event *s*. |
| 2327 | |
| 2328 | Parameters |
| 2329 | ---------- |
| 2330 | s : str |
| 2331 | One of the following events ids: |
| 2332 | |
| 2333 | - 'button_press_event' |
| 2334 | - 'button_release_event' |
| 2335 | - 'draw_event' |
| 2336 | - 'key_press_event' |
| 2337 | - 'key_release_event' |
| 2338 | - 'motion_notify_event' |
| 2339 | - 'pick_event' |
| 2340 | - 'resize_event' |
| 2341 | - 'scroll_event' |
| 2342 | - 'figure_enter_event', |
| 2343 | - 'figure_leave_event', |
| 2344 | - 'axes_enter_event', |
| 2345 | - 'axes_leave_event' |
| 2346 | - 'close_event'. |
| 2347 | |
| 2348 | func : callable |
| 2349 | The callback function to be executed, which must have the |
| 2350 | signature:: |
| 2351 | |
| 2352 | def func(event: Event) -> Any |
| 2353 | |
| 2354 | For the location events (button and key press/release), if the |
| 2355 | mouse is over the Axes, the ``inaxes`` attribute of the event will |
| 2356 | be set to the `~matplotlib.axes.Axes` the event occurs is over, and |
| 2357 | additionally, the variables ``xdata`` and ``ydata`` attributes will |
| 2358 | be set to the mouse location in data coordinates. See `.KeyEvent` |
| 2359 | and `.MouseEvent` for more info. |
| 2360 | |
| 2361 | .. note:: |
| 2362 | |
| 2363 | If func is a method, this only stores a weak reference to the |
| 2364 | method. Thus, the figure does not influence the lifetime of |
| 2365 | the associated object. Usually, you want to make sure that the |
| 2366 | object is kept alive throughout the lifetime of the figure by |
| 2367 | holding a reference to it. |
| 2368 | |
| 2369 | Returns |
| 2370 | ------- |
| 2371 | cid |
| 2372 | A connection id that can be used with |
| 2373 | `.FigureCanvasBase.mpl_disconnect`. |
| 2374 | |
| 2375 | Examples |
| 2376 | -------- |
| 2377 | :: |
| 2378 | |
| 2379 | def on_press(event): |
| 2380 | print('you pressed', event.button, event.xdata, event.ydata) |
| 2381 |