@@ -70,15 +70,17 @@ Event attributes
7070================
7171
7272All matplotlib events inherit from the base class
73- :class: `matplotlib.backend_bases.Event `, which store the attributes
73+ :class: `matplotlib.backend_bases.Event `, which store the attributes:
74+
75+ ``name ``
76+ the event name
77+
78+ ``canvas ``
79+ the FigureCanvas instance generating the event
80+
81+ ``guiEvent ``
82+ the GUI event that triggered the matplotlib event
7483
75- =============== =================================================
76- Event attribute Description
77- =============== =================================================
78- ``name `` the event name
79- ``canvas `` the FigureCanvas instance generating the event
80- ``guiEvent `` the GUI event that triggered the matplotlib event
81- =============== =================================================
8284
8385The most common events that are the bread and butter of event handling
8486are key press/release events and mouse press/release and movement
@@ -87,16 +89,20 @@ events. The :class:`~matplotlib.backend_bases.KeyEvent` and
8789these events are both derived from the LocationEvent, which has the
8890following attributes
8991
90- ======================= ========================================
91- LocationEvent attribute Description
92- ======================= ========================================
93- ``x `` x position - pixels from left of canvas
94- ``y `` y position - pixels from right of canvas
95- ``button `` button pressed None, 1, 2, 3
96- ``inaxes `` the Axes instance if mouse us over axes
97- ``xdata `` x coord of mouse in data coords
98- ``ydata `` y coord of mouse in data coords
99- ======================= ========================================
92+ ``x ``
93+ x position - pixels from left of canvas
94+
95+ ``y ``
96+ y position - pixels from bottom of canvas
97+
98+ ``inaxes ``
99+ the :class: `~matplotlib.axes.Axes ` instance if mouse is over axes
100+
101+ ``xdata ``
102+ x coord of mouse in data coords
103+
104+ ``ydata ``
105+ y coord of mouse in data coords
100106
101107Let's look a simple example of a canvas, where a simple line segment
102108is created every time a mouse is pressed::
@@ -129,12 +135,11 @@ The :class:`~matplotlib.backend_bases.MouseEvent` that we just used is a
129135the data and pixel coordinates in event.x and event.xdata. In
130136addition to the ``LocationEvent `` attributes, it has
131137
132- ==================== ==============================================================
133- MouseEvent attribute Description
134- ==================== ==============================================================
135- ``button `` button pressed None, 1, 2, 3
136- ``key `` the key pressed: None, chr(range(255)), shift, win, or control
137- ==================== ==============================================================
138+ ``button ``
139+ button pressed None, 1, 2, 3, 'up', 'down' (up and down are used for scroll events)
140+
141+ ``key ``
142+ the key pressed: None, chr(range(255), 'shift', 'win', or 'control'
138143
139144Draggable Rectangle Exercise
140145----------------------------
@@ -281,7 +286,6 @@ Extra credit solution::
281286 self.rect.set_x(x0+dx)
282287 self.rect.set_y(y0+dy)
283288
284-
285289 canvas = self.rect.figure.canvas
286290 axes = self.rect.axes
287291 # restore the background region
@@ -293,8 +297,6 @@ Extra credit solution::
293297 # blit just the redrawn area
294298 canvas.blit(axes.bbox)
295299
296-
297-
298300 def on_release(self, event):
299301 'on release we reset the press data'
300302 if DraggableRectangle.lock is not self:
@@ -309,6 +311,7 @@ Extra credit solution::
309311
310312 # redraw the full figure
311313 self.rect.figure.canvas.draw()
314+
312315 def disconnect(self):
313316 'disconnect all the stored connection ids'
314317 self.rect.figure.canvas.mpl_disconnect(self.cidpress)
@@ -340,24 +343,29 @@ You can enable picking by setting the ``picker`` property of an
340343
341344There are a variety of meanings of the ``picker `` property:
342345
343- - ``None `` : picking is disabled for this artist (default)
346+ ``None ``
347+ picking is disabled for this artist (default)
344348
345- - ``boolean `` : if True then picking will be enabled and the artist will
346- fire a pick event if the mouse event is over the artist
349+ ``boolean ``
350+ if True then picking will be enabled and the artist will fire a
351+ pick event if the mouse event is over the artist
347352
348- - ``float `` : if picker is a number it is interpreted as an epsilon
349- tolerance in points and the the artist will fire off an event if its
350- data is within epsilon of the mouse event. For some artists like
351- lines and patch collections, the artist may provide additional data
352- to the pick event that is generated, eg the indices of the data
353- within epsilon of the pick event.
353+ ``float ``
354+ if picker is a number it is interpreted as an epsilon tolerance in
355+ points and the the artist will fire off an event if its data is
356+ within epsilon of the mouse event. For some artists like lines
357+ and patch collections, the artist may provide additional data to
358+ the pick event that is generated, eg the indices of the data
359+ within epsilon of the pick event.
354360
355- - ``function `` : if picker is callable, it is a user supplied function
356- which determines whether the artist is hit by the mouse event. The
357- signature is ``hit, props = picker(artist, mouseevent) `` to
358- determine the hit test. If the mouse event is over the artist,
359- return ``hit=True `` and props is a dictionary of properties you want
360- added to the :class: `~matplotlib.backend_bases.PickEvent ` attributes
361+ ``function ``
362+ if picker is callable, it is a user supplied function which
363+ determines whether the artist is hit by the mouse event. The
364+ signature is ``hit, props = picker(artist, mouseevent) `` to
365+ determine the hit test. If the mouse event is over the artist,
366+ return ``hit=True `` and props is a dictionary of properties you
367+ want added to the :class: `~matplotlib.backend_bases.PickEvent `
368+ attributes
361369
362370
363371After you have enabled an artist for picking by setting the ``picker ``
@@ -373,16 +381,18 @@ pick callbacks on mouse press events. Eg::
373381The :class: `~matplotlib.backend_bases.PickEvent ` which is passed to
374382your callback is always fired with two attributes:
375383
376- - ``mouseevent `` : the mouse event that generate the pick event. The
377- mouse event in turn has attributes like ``x `` and ``y `` (the coords in
378- display space, eg pixels from left, bottom) and xdata, ydata (the
379- coords in data space). Additionally, you can get information about
380- which buttons were pressed, which keys were pressed, which Axes the
381- mouse is over, etc. See :class: `matplotlib.backend_bases.MouseEvent ` for
382- details.
383-
384- - ``artist `` : the :class: `matplotlib.artist.Artist ` that generated
385- the pick event.
384+ ``mouseevent `` the mouse event that generate the pick event. The
385+ mouse event in turn has attributes like ``x `` and ``y `` (the
386+ coords in display space, eg pixels from left, bottom) and xdata,
387+ ydata (the coords in data space). Additionally, you can get
388+ information about which buttons were pressed, which keys were
389+ pressed, which :class: `~matplotlib.axes.Axes ` the mouse is over,
390+ etc. See :class: `matplotlib.backend_bases.MouseEvent ` for
391+ details.
392+
393+ ``artist ``
394+ the :class: `~matplotlib.artist.Artist ` that generated the pick
395+ event.
386396
387397Additionally, certain artists like :class: `~matplotlib.lines.Line2D `
388398and :class: `~matplotlib.collections.PatchCollection ` may attach
0 commit comments