1919 :class:`MouseEvent` store the meta data like keys and buttons
2020 pressed, x and y locations in pixel and
2121 :class:`~matplotlib.axes.Axes` coordinates.
22+
2223"""
2324
2425from __future__ import division
@@ -38,17 +39,17 @@ class RendererBase:
3839
3940 The following methods *must* be implemented in the backend:
4041
41- * draw_path
42- * draw_image
43- * draw_text
44- * get_text_width_height_descent
42+ * :meth:` draw_path`
43+ * :meth:` draw_image`
44+ * :meth:` draw_text`
45+ * :meth:` get_text_width_height_descent`
4546
4647 The following methods *should* be implemented in the backend for
4748 optimization reasons:
4849
49- * draw_markers
50- * draw_path_collection
51- * draw_quad_mesh
50+ * :meth:` draw_markers`
51+ * :meth:` draw_path_collection`
52+ * :meth:` draw_quad_mesh`
5253 """
5354 def __init__ (self ):
5455 self ._texmanager = None
@@ -81,8 +82,14 @@ def draw_markers(self, gc, marker_path, marker_trans, path, trans, rgbFace=None)
8182 that behavior, those vertices should be removed before calling
8283 this function.
8384
84- ``marker_trans`` is an affine transform applied to the marker.
85- ``trans`` is an affine transform applied to the path.
85+ ``gc``
86+ the :class:`GraphicsContextBase` instance
87+
88+ ``marker_trans``
89+ is an affine transform applied to the marker.
90+
91+ ``trans``
92+ is an affine transform applied to the path.
8693
8794 This provides a fallback implementation of draw_markers that
8895 makes multiple calls to
@@ -271,14 +278,23 @@ def get_image_magnification(self):
271278
272279 def draw_image (self , x , y , im , bbox , clippath = None , clippath_trans = None ):
273280 """
274- Draw the :class:`~matplotlib.image.Image` instance into the
275- current axes; ``x`` is the distance in pixels from the left
276- hand side of the canvas. ``y`` is the distance from the
277- origin. That is, if origin is upper, y is the distance from
278- top. If origin is lower, y is the distance from bottom
281+ Draw the image instance into the current axes;
282+
283+ ``x``
284+ is the distance in pixels from the left hand side of the canvas.
285+
286+ ``y``
287+ the distance from the origin. That is, if origin is
288+ upper, y is the distance from top. If origin is lower, y
289+ is the distance from bottom
290+
291+ ``im``
292+ the :class:`matplotlib._image.Image` instance
293+
294+ ``bbox``
295+ a :class:`matplotlib.transforms.Bbox` instance for clipping, or
296+ None
279297
280- bbox is a :class:`~matplotlib.transforms.Bbox` instance for clipping, or
281- None
282298 """
283299 raise NotImplementedError
284300
@@ -294,18 +310,33 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!'):
294310
295311 def draw_text (self , gc , x , y , s , prop , angle , ismath = False ):
296312 """
297- Draw the :class:`~matplotlib.text.Text` instance s at ``x``,
298- ``y`` (display coords) with
299- :class:`~matplotlib.font_manager.FontProperties` instance
300- ``prop`` at ``angle`` in degrees, using :class:`GraphicsContextBase` gc
313+ Draw the text instance
314+
315+ ``gc``
316+ the :class:`GraphicsContextBase` instance
317+
318+ ``x``
319+ the x location of the text in display coords
320+
321+ ``y``
322+ the y location of the text in display coords
323+
324+ ``s``
325+ a :class:`matplotlib.text.Text` instance
326+
327+ ``prop``
328+ a :class:`matplotlib.font_manager.FontProperties` instance
329+
330+ ``angle``
331+ the rotation angle in degrees
301332
302333 **backend implementers note**
303334
304335 When you are trying to determine if you have gotten your bounding box
305336 right (which is what enables the text layout/alignment to work
306- properly), it helps to change the line in text.py
337+ properly), it helps to change the line in text.py::
307338
308- if 0: bbox_artist(self, renderer)
339+ if 0: bbox_artist(self, renderer)
309340
310341 to if 1, and then the actual bounding box will be blotted along with
311342 your text.
@@ -326,7 +357,7 @@ def get_canvas_width_height(self):
326357
327358 def get_texmanager (self ):
328359 """
329- return the :class:matplotlib.texmanager.TexManager` instance
360+ return the :class:` matplotlib.texmanager.TexManager` instance
330361 """
331362 if self ._texmanager is None :
332363 from matplotlib .texmanager import TexManager
@@ -350,12 +381,15 @@ def new_gc(self):
350381 def points_to_pixels (self , points ):
351382 """
352383 Convert points to display units
353- points - a float or a numpy array of float
384+
385+ ``points``
386+ a float or a numpy array of float
387+
354388 return points converted to pixels
355389
356- You need to override this function (unless your backend doesn't have a
357- dpi, eg, postscript or svg).
358- Some imaging systems assume some value for pixels per inch""
390+ You need to override this function (unless your backend
391+ doesn't have a dpi, eg, postscript or svg). Some imaging
392+ systems assume some value for pixels per inch::
359393
360394 points to pixels = points * pixels_per_inch/72.0 * dpi/72.0
361395 """
@@ -530,6 +564,7 @@ def set_dashes(self, dash_offset, dash_list):
530564
531565 ``dash_list``
532566 specifies the on-off sequence as points. ``(None, None)`` specifies a solid line
567+
533568 """
534569 self ._dashes = dash_offset , dash_list
535570
@@ -620,6 +655,7 @@ class DrawEvent(Event):
620655
621656 ``renderer``
622657 the :class:`RendererBase` instance for the draw event
658+
623659 """
624660 def __init__ (self , name , canvas , renderer ):
625661 Event .__init__ (self , name , canvas )
@@ -636,6 +672,7 @@ class ResizeEvent(Event):
636672
637673 ``height``
638674 height of the canvas in pixels
675+
639676 """
640677 def __init__ (self , name , canvas ):
641678 Event .__init__ (self , name , canvas )
@@ -716,8 +753,17 @@ class MouseEvent(LocationEvent):
716753
717754 ``button``
718755 button pressed None, 1, 2, 3, 'up', 'down' (up and down are used for scroll events)
756+
719757 ``key``
720- the key pressed: None, chr(range(255), shift, win, or control
758+ the key pressed: None, chr(range(255), 'shift', 'win', or 'control'
759+
760+
761+ Example usage::
762+
763+ def on_press(event):
764+ print 'you pressed', event.button, event.xdata, event.ydata
765+
766+ cid = fig.canvas.mpl_connect('button_press_event', on_press)
721767
722768 """
723769 x = None # x position - pixels from left of canvas
@@ -750,10 +796,25 @@ class PickEvent(Event):
750796 ``artist``
751797 the :class:`~matplotlib.artist.Artist` picked
752798
753- extra class dependent attrs -- eg a
754- :class:`~matplotlib.lines.Line2D` pick may define different extra
755- attributes than a :class:`~matplotlib.collections.PatchCollection`
756- pick event
799+ other
800+ extra class dependent attrs -- eg a
801+ :class:`~matplotlib.lines.Line2D` pick may define different
802+ extra attributes than a
803+ :class:`~matplotlib.collections.PatchCollection` pick event
804+
805+
806+ Example usage::
807+
808+ line, = ax.plot(rand(100), 'o', picker=5) # 5 points tolerance
809+
810+ def on_pick(event):
811+ thisline = event.artist
812+ xdata, ydata = thisline.get_data()
813+ ind = event.ind
814+ print 'on pick line:', zip(xdata[ind], ydata[ind])
815+
816+ cid = fig.canvas.mpl_connect('pick_event', on_pick)
817+
757818 """
758819 def __init__ (self , name , canvas , mouseevent , artist , guiEvent = None , ** kwargs ):
759820 Event .__init__ (self , name , canvas , guiEvent )
@@ -776,7 +837,16 @@ class KeyEvent(LocationEvent):
776837 the key pressed: None, chr(range(255), shift, win, or control
777838
778839 This interface may change slightly when better support for
779- modifier keys is included
840+ modifier keys is included.
841+
842+
843+ Example usage::
844+
845+ def on_key(event):
846+ print 'you pressed', event.key, event.xdata, event.ydata
847+
848+ cid = fig.canvas.mpl_connect('key_press_event', on_key)
849+
780850 """
781851 def __init__ (self , name , canvas , key , x = 0 , y = 0 , guiEvent = None ):
782852 LocationEvent .__init__ (self , name , canvas , x , y , guiEvent = guiEvent )
@@ -1001,8 +1071,17 @@ def button_press_event(self, x, y, button, guiEvent=None):
10011071 def button_release_event (self , x , y , button , guiEvent = None ):
10021072 """
10031073 Backend derived classes should call this function on any mouse
1004- button release. x,y are the canvas coords: 0,0 is lower, left.
1005- button and key are as defined in :class:`MouseEvent`
1074+ button release.
1075+
1076+ ``x``
1077+ the canvas coordinates where 0=left
1078+
1079+ ``y``
1080+ the canvas coordinates where 0=bottom
1081+
1082+ ``guiEvent``
1083+ the native UI event that generated the mpl event
1084+
10061085
10071086 This method will be call all functions connected to the
10081087 'button_release_event' with a :class:`MouseEvent` instance.
@@ -1016,8 +1095,17 @@ def button_release_event(self, x, y, button, guiEvent=None):
10161095 def motion_notify_event (self , x , y , guiEvent = None ):
10171096 """
10181097 Backend derived classes should call this function on any
1019- motion-notify-event. x,y are the canvas coords: 0,0 is lower, left.
1020- button and key are as defined in MouseEvent
1098+ motion-notify-event.
1099+
1100+ ``x``
1101+ the canvas coordinates where 0=left
1102+
1103+ ``y``
1104+ the canvas coordinates where 0=bottom
1105+
1106+ ``guiEvent``
1107+ the native UI event that generated the mpl event
1108+
10211109
10221110 This method will be call all functions connected to the
10231111 'motion_notify_event' with a :class:`MouseEvent` instance.
@@ -1241,26 +1329,42 @@ def func(event)
12411329 - 'resize_event'
12421330 - 'scroll_event'
12431331
1244- For the three events above, if the mouse is over the axes,
1245- the variable event.inaxes will be set to the axes it is over,
1246- and additionally, the variables event.xdata and event.ydata
1247- will be defined. This is the mouse location in data coords.
1248- See :class`MplEvent`
1332+ For the location events (button and key press/release), if the
1333+ mouse is over the axes, the variable event.inaxes will be set
1334+ to the :class:`~matplotlib.axes.Axes` the event occurs is
1335+ over, and additionally, the variables ``event.xdata`` and
1336+ ``event.ydata`` will be defined. This is the mouse location in
1337+ data coords. See :class:`KeyEvent` and:class:`MouseEvent` for more info.
12491338
12501339 return value is a connection id that can be used with
1251- :meth:`mpl_disconnect`
1340+ :meth:`mpl_disconnect`.
1341+
1342+ Example usage::
1343+
1344+ def on_press(event):
1345+ print 'you pressed', event.button, event.xdata, event.ydata
1346+
1347+ cid = canvas.mpl_connect('button_press_event', on_press)
1348+
12521349 """
12531350
12541351 return self .callbacks .connect (s , func )
12551352
12561353 def mpl_disconnect (self , cid ):
12571354 """
12581355 disconnect callback id cid
1356+
1357+ Example usage::
1358+
1359+ cid = canvas.mpl_connect('button_press_event', on_press)
1360+ #...later
1361+ canvas.mpl_disconnect(cid)
12591362 """
12601363 return self .callbacks .disconnect (cid )
12611364
12621365 def flush_events (self ):
1263- """ Flush the GUI events for the figure. Implemented only for
1366+ """
1367+ Flush the GUI events for the figure. Implemented only for
12641368 backends with GUIs.
12651369 """
12661370 raise NotImplementedError
@@ -1365,28 +1469,33 @@ class NavigationToolbar2:
13651469
13661470 They must also define
13671471
1368- * save_figure - save the current figure
1472+ :meth:`save_figure`
1473+ save the current figure
13691474
1370- * set_cursor - if you want the pointer icon to change
1475+ :meth:`set_cursor`
1476+ if you want the pointer icon to change
13711477
1372- * _init_toolbar - create your toolbar widget
1478+ :meth:`_init_toolbar`
1479+ create your toolbar widget
13731480
1374- * draw_rubberband (optional) : draw the zoom to rect
1375- "rubberband" rectangle
1481+ :meth:` draw_rubberband` (optional)
1482+ draw the zoom to rect "rubberband" rectangle
13761483
1377- * press : (optional) whenever a mouse button is pressed, you'll be
1378- notified with the event
1484+ :meth:`press` (optional)
1485+ whenever a mouse button is pressed, you'll be
1486+ notified with the event
13791487
1380- * release : (optional) whenever a mouse button is released,
1381- you'll be notified with the event
1488+ :meth:` release` (optional)
1489+ whenever a mouse button is released, you'll be notified with the event
13821490
1383- * dynamic_update (optional) dynamically update the window while
1384- navigating
1491+ :meth:` dynamic_update` ptional)
1492+ dynamically update the window while navigating
13851493
1386- * set_message (optional) - display message
1494+ :meth:`set_message` ptional)
1495+ display message
13871496
1388- * set_history_buttons (optional) - you can change the history
1389- back / forward buttons to indicate disabled / enabled state.
1497+ :meth:` set_history_buttons` (optional)
1498+ you can change the history back / forward buttons to indicate disabled / enabled state.
13901499
13911500 That's it, we'll do the rest!
13921501 """
0 commit comments