List of events

Event_name 

class 

Description

button_press_event MouseEvent  The mouse button is pressed
button_release_event MouseEvent  The mouse button is released
draw_event DrawEvent   The canvas draw occurs
key_press_event KeyEvent  A key is pressed
key_release_event KeyEvent  A key is released
motion_notify_event MouseEvent  The motion of the mouse
pick_event PickEvent  An object in the canvas is selected
resize_event  ResizeEvent  The figure canvas is resized
scroll_event   MouseEvent  The scroll wheel of the mouse is rolled
figure_enter_event  LocationEvent The mouse enters a figure
axes_enter_event LocationEvent The mouse enters an axes object
axes_leave_event LocationEvent  The mouse leaves an axes object
figure_leave_event LocationEvent The mouse leaves a figure

Note: That the classes are defined in matplotlib.backend_bases

Event Handling in Matplotlib

Event based System usually is part of a recurring set of patterns. Often, they comprise of the following :

  • An incoming event
  • A mechanism that is used to respond to an event
  • A looping construct (e.g. while loop, listener, and the message dispatch mechanism)

The events that are triggered are also a bit richer, including information like which Axes the event occurred in. The events also understand the Matplotlib coordinate system and report event locations in both pixel and data coordinates.

Syntax:

figure.canvas.mpl_connect( Event_name , callback function or method)

Parameters:

  • Event_name: It could be any from the below table
  • callback_function: It will define to handle the event.

Similar Reads

List of events

Event_name  class  Description button_press_event MouseEvent  The mouse button is pressed button_release_event MouseEvent  The mouse button is released draw_event DrawEvent   The canvas draw occurs key_press_event KeyEvent  A key is pressed key_release_event KeyEvent  A key is released motion_notify_event MouseEvent  The motion of the mouse pick_event PickEvent  An object in the canvas is selected resize_event  ResizeEvent  The figure canvas is resized scroll_event   MouseEvent  The scroll wheel of the mouse is rolled figure_enter_event  LocationEvent The mouse enters a figure axes_enter_event LocationEvent The mouse enters an axes object axes_leave_event LocationEvent  The mouse leaves an axes object figure_leave_event LocationEvent The mouse leaves a figure...

MOUSE EVENT

button_press_event: This event involves a mouse button press button_release_event: This event involves a mouse button release scroll_event: This event involves scrolling of the mouse motion_notify_event: This event involves a notification pertaining to the mouse movement...