matplotlib 3.5.1

ParametersReturns
connect(s, func)

Parameters

s : str

One of the following events ids:

  • 'button_press_event'

  • 'button_release_event'

  • 'draw_event'

  • 'key_press_event'

  • 'key_release_event'

  • 'motion_notify_event'

  • 'pick_event'

  • 'resize_event'

  • 'scroll_event'

  • 'figure_enter_event',

  • 'figure_leave_event',

  • 'axes_enter_event',

  • 'axes_leave_event'

  • 'close_event'.

func : callable

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.

Returns

cid

A connection id that can be used with .FigureCanvasBase.mpl_disconnect .

Bind function func to event s.

Examples

def on_press(event):

print('you pressed', event.button, event.xdata, event.ydata)

cid = canvas.mpl_connect('button_press_event', on_press)

See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /matplotlib/pyplot.py#883
type: <class 'function'>
Commit: