Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6175c3

Browse files
authored
Merge pull request #15888 from anntzer/backend_bases-docs
Cleanup backend_bases docs.
2 parents 04668b7 + 08d68ee commit b6175c3

File tree

1 file changed

+69
-87
lines changed

1 file changed

+69
-87
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 69 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
11
"""
22
Abstract base classes define the primitives that renderers and
3-
graphics contexts must implement to serve as a matplotlib backend
3+
graphics contexts must implement to serve as a Matplotlib backend.
44
5-
:class:`RendererBase`
5+
`RendererBase`
66
An abstract base class to handle drawing/rendering operations.
77
8-
:class:`FigureCanvasBase`
9-
The abstraction layer that separates the
10-
:class:`matplotlib.figure.Figure` from the backend specific
11-
details like a user interface drawing area
8+
`FigureCanvasBase`
9+
The abstraction layer that separates the `.Figure` from the backend
10+
specific details like a user interface drawing area.
1211
13-
:class:`GraphicsContextBase`
14-
An abstract base class that provides color, line styles, etc...
12+
`GraphicsContextBase`
13+
An abstract base class that provides color, line styles, etc.
1514
16-
:class:`Event`
17-
The base class for all of the matplotlib event
18-
handling. Derived classes such as :class:`KeyEvent` and
19-
:class:`MouseEvent` store the meta data like keys and buttons
20-
pressed, x and y locations in pixel and
21-
:class:`~matplotlib.axes.Axes` coordinates.
15+
`Event`
16+
The base class for all of the Matplotlib event handling. Derived classes
17+
such as `KeyEvent` and `MouseEvent` store the meta data like keys and
18+
buttons pressed, x and y locations in pixel and `~.axes.Axes` coordinates.
2219
23-
:class:`ShowBase`
24-
The base class for the Show class of each interactive backend;
25-
the 'show' callable is then set to Show.__call__, inherited from
26-
ShowBase.
20+
`ShowBase`
21+
The base class for the ``Show`` class of each interactive backend; the
22+
'show' callable is then set to ``Show.__call__``.
2723
28-
:class:`ToolContainerBase`
29-
The base class for the Toolbar class of each interactive backend.
24+
`ToolContainerBase`
25+
The base class for the Toolbar class of each interactive backend.
3026
31-
:class:`StatusbarBase`
27+
`StatusbarBase`
3228
The base class for the messaging area.
3329
"""
3430

@@ -470,13 +466,13 @@ def draw_image(self, gc, x, y, im, transform=None):
470466
transform : `matplotlib.transforms.Affine2DBase`
471467
If and only if the concrete backend is written such that
472468
:meth:`option_scale_image` returns ``True``, an affine
473-
transformation *may* be passed to :meth:`draw_image`. It takes the
474-
form of a :class:`~matplotlib.transforms.Affine2DBase` instance.
475-
The translation vector of the transformation is given in physical
476-
units (i.e., dots or pixels). Note that the transformation does not
477-
override *x* and *y*, and has to be applied *before* translating
478-
the result by *x* and *y* (this can be accomplished by adding *x*
479-
and *y* to the translation vector defined by *transform*).
469+
transformation (i.e., an `.Affine2DBase`) *may* be passed to
470+
:meth:`draw_image`. The translation vector of the transformation
471+
is given in physical units (i.e., dots or pixels). Note that
472+
the transformation does not override *x* and *y*, and has to be
473+
applied *before* translating the result by *x* and *y* (this can
474+
be accomplished by adding *x* and *y* to the translation vector
475+
defined by *transform*).
480476
"""
481477
raise NotImplementedError
482478

@@ -584,7 +580,7 @@ def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath):
584580
s : str
585581
The text to be converted.
586582
usetex : bool
587-
Whether to use matplotlib usetex mode.
583+
Whether to use usetex mode.
588584
ismath : bool or "TeX"
589585
If True, use mathtext parser. If "TeX", use *usetex* mode.
590586
"""
@@ -598,7 +594,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
598594
"""
599595
Get the width, height, and descent (offset from the bottom
600596
to the baseline), in display coords, of the string *s* with
601-
:class:`~matplotlib.font_manager.FontProperties` *prop*
597+
`.FontProperties` *prop*.
602598
"""
603599
if ismath == 'TeX':
604600
# todo: handle props
@@ -782,7 +778,7 @@ def get_clip_rectangle(self):
782778
def get_clip_path(self):
783779
"""
784780
Return the clip path in the form (path, transform), where path
785-
is a :class:`~matplotlib.path.Path` instance, and transform is
781+
is a `~.path.Path` instance, and transform is
786782
an affine transform to apply to the path before clipping.
787783
"""
788784
if self._clippath is not None:
@@ -1191,21 +1187,18 @@ def _on_timer(self):
11911187

11921188
class Event:
11931189
"""
1194-
A matplotlib event. Attach additional attributes as defined in
1190+
A Matplotlib event. Attach additional attributes as defined in
11951191
:meth:`FigureCanvasBase.mpl_connect`. The following attributes
11961192
are defined and shown with their default values
11971193
11981194
Attributes
11991195
----------
12001196
name : str
1201-
the event name
1202-
1197+
The event name.
12031198
canvas : `FigureCanvasBase`
1204-
the backend-specific canvas instance generating the event
1205-
1199+
The backend-specific canvas instance generating the event.
12061200
guiEvent
1207-
the GUI event that triggered the matplotlib event
1208-
1201+
The GUI event that triggered the Matplotlib event.
12091202
"""
12101203
def __init__(self, name, canvas, guiEvent=None):
12111204
self.name = name
@@ -1227,14 +1220,13 @@ class DrawEvent(Event):
12271220
Calling ``canvas.draw`` and ``canvas.blit`` in these callbacks may
12281221
not be safe with all backends and may cause infinite recursion.
12291222
1230-
In addition to the :class:`Event` attributes, the following event
1223+
In addition to the `Event` attributes, the following event
12311224
attributes are defined:
12321225
12331226
Attributes
12341227
----------
12351228
renderer : `RendererBase`
1236-
the renderer for the draw event
1237-
1229+
The renderer for the draw event.
12381230
"""
12391231
def __init__(self, name, canvas, renderer):
12401232
Event.__init__(self, name, canvas)
@@ -1245,17 +1237,15 @@ class ResizeEvent(Event):
12451237
"""
12461238
An event triggered by a canvas resize
12471239
1248-
In addition to the :class:`Event` attributes, the following event
1240+
In addition to the `Event` attributes, the following event
12491241
attributes are defined:
12501242
12511243
Attributes
12521244
----------
12531245
width : scalar
1254-
width of the canvas in pixels
1255-
1246+
Width of the canvas in pixels.
12561247
height : scalar
1257-
height of the canvas in pixels
1258-
1248+
Height of the canvas in pixels.
12591249
"""
12601250
def __init__(self, name, canvas):
12611251
Event.__init__(self, name, canvas)
@@ -1273,25 +1263,21 @@ class LocationEvent(Event):
12731263
The following additional attributes are defined and shown with
12741264
their default values.
12751265
1276-
In addition to the :class:`Event` attributes, the following
1266+
In addition to the `Event` attributes, the following
12771267
event attributes are defined:
12781268
12791269
Attributes
12801270
----------
12811271
x : scalar
1282-
x position - pixels from left of canvas
1283-
1272+
x position - pixels from left of canvas.
12841273
y : scalar
1285-
y position - pixels from bottom of canvas
1286-
1287-
inaxes : bool
1288-
the :class:`~matplotlib.axes.Axes` instance if mouse is over axes
1289-
1290-
xdata : scalar
1291-
x coord of mouse in data coords
1292-
1293-
ydata : scalar
1294-
y coord of mouse in data coords
1274+
y position - pixels from bottom of canvas.
1275+
inaxes : `~.axes.Axes` or None
1276+
The `~.axes.Axes` instance over which the mouse is, if any.
1277+
xdata : float or None
1278+
x data coordinate of the mouse.
1279+
ydata : float or None
1280+
y data coordinate of the mouse.
12951281
"""
12961282

12971283
lastevent = None # the last event that was triggered before this one
@@ -1373,13 +1359,12 @@ class MouseEvent(LocationEvent):
13731359
'scroll_event',
13741360
'motion_notify_event').
13751361
1376-
In addition to the :class:`Event` and :class:`LocationEvent`
1362+
In addition to the `Event` and `LocationEvent`
13771363
attributes, the following attributes are defined:
13781364
13791365
Attributes
13801366
----------
1381-
button : {None, MouseButton.LEFT, MouseButton.MIDDLE, MouseButton.RIGHT, \
1382-
'up', 'down'}
1367+
button : None or `MouseButton` or {'up', 'down'}
13831368
The button pressed. 'up' and 'down' are used for scroll events.
13841369
Note that in the nbagg backend, both the middle and right clicks
13851370
return RIGHT since right clicking will bring up the context menu in
@@ -1437,21 +1422,18 @@ class PickEvent(Event):
14371422
A pick event, fired when the user picks a location on the canvas
14381423
sufficiently close to an artist.
14391424
1440-
Attrs: all the :class:`Event` attributes plus
1425+
Attrs: all the `Event` attributes plus
14411426
14421427
Attributes
14431428
----------
14441429
mouseevent : `MouseEvent`
1445-
the mouse event that generated the pick
1446-
1430+
The mouse event that generated the pick.
14471431
artist : `matplotlib.artist.Artist`
1448-
the picked artist
1449-
1432+
The picked artist.
14501433
other
1451-
extra class dependent attrs -- e.g., a
1452-
:class:`~matplotlib.lines.Line2D` pick may define different
1453-
extra attributes than a
1454-
:class:`~matplotlib.collections.PatchCollection` pick event
1434+
Additional attributes may be present depending on the type of the
1435+
picked object; e.g., a `~.Line2D` pick may define different extra
1436+
attributes than a `~.PatchCollection` pick.
14551437
14561438
Examples
14571439
--------
@@ -1483,7 +1465,7 @@ class KeyEvent(LocationEvent):
14831465
Attach additional attributes as defined in
14841466
:meth:`FigureCanvasBase.mpl_connect`.
14851467
1486-
In addition to the :class:`Event` and :class:`LocationEvent`
1468+
In addition to the `Event` and `LocationEvent`
14871469
attributes, the following attributes are defined:
14881470
14891471
Attributes
@@ -1556,7 +1538,7 @@ class FigureCanvasBase:
15561538
Attributes
15571539
----------
15581540
figure : `matplotlib.figure.Figure`
1559-
A high-level figure instance
1541+
A high-level figure instance.
15601542
"""
15611543

15621544
# Set to one of {"qt5", "qt4", "gtk3", "wx", "tk", "macosx"} if an
@@ -1714,7 +1696,7 @@ def pick_event(self, mouseevent, artist, **kwargs):
17141696
Callback processing for pick events.
17151697
17161698
This method will be called by artists who are picked and will
1717-
fire off :class:`PickEvent` callbacks registered listeners.
1699+
fire off `PickEvent` callbacks registered listeners.
17181700
"""
17191701
s = 'pick_event'
17201702
event = PickEvent(s, self, mouseevent, artist,
@@ -1728,10 +1710,10 @@ def scroll_event(self, x, y, step, guiEvent=None):
17281710
17291711
Backend derived classes should call this function on any
17301712
scroll wheel event. (*x*, *y*) are the canvas coords ((0, 0) is lower
1731-
left). button and key are as defined in MouseEvent.
1713+
left). button and key are as defined in `MouseEvent`.
17321714
1733-
This method will be call all functions connected to the
1734-
'scroll_event' with a :class:`MouseEvent` instance.
1715+
This method will callall functions connected to the 'scroll_event' with
1716+
a `MouseEvent` instance.
17351717
"""
17361718
if step >= 0:
17371719
self._button = 'up'
@@ -1748,10 +1730,10 @@ def button_press_event(self, x, y, button, dblclick=False, guiEvent=None):
17481730
17491731
Backend derived classes should call this function on any mouse
17501732
button press. (*x*, *y*) are the canvas coords ((0, 0) is lower left).
1751-
button and key are as defined in :class:`MouseEvent`.
1733+
button and key are as defined in `MouseEvent`.
17521734
1753-
This method will be call all functions connected to the
1754-
'button_press_event' with a :class:`MouseEvent` instance.
1735+
This method will callall functions connected to the
1736+
'button_press_event' with a `MouseEvent` instance.
17551737
"""
17561738
self._button = button
17571739
s = 'button_press_event'
@@ -1767,7 +1749,7 @@ def button_release_event(self, x, y, button, guiEvent=None):
17671749
button release.
17681750
17691751
This method will call all functions connected to the
1770-
'button_release_event' with a :class:`MouseEvent` instance.
1752+
'button_release_event' with a `MouseEvent` instance.
17711753
17721754
Parameters
17731755
----------
@@ -1791,7 +1773,7 @@ def motion_notify_event(self, x, y, guiEvent=None):
17911773
motion-notify-event.
17921774
17931775
This method will call all functions connected to the
1794-
'motion_notify_event' with a :class:`MouseEvent` instance.
1776+
'motion_notify_event' with a `MouseEvent` instance.
17951777
17961778
Parameters
17971779
----------
@@ -1897,7 +1879,7 @@ def release_mouse(self, ax):
18971879
self.mouse_grabber = None
18981880

18991881
def draw(self, *args, **kwargs):
1900-
"""Render the :class:`~matplotlib.figure.Figure`."""
1882+
"""Render the `.Figure`."""
19011883

19021884
def draw_idle(self, *args, **kwargs):
19031885
"""
@@ -2313,11 +2295,11 @@ def key_press_handler(event, canvas, toolbar=None):
23132295
23142296
Parameters
23152297
----------
2316-
event : :class:`KeyEvent`
2298+
event : `KeyEvent`
23172299
a key press/release event
2318-
canvas : :class:`FigureCanvasBase`
2300+
canvas : `FigureCanvasBase`
23192301
the backend-specific canvas instance
2320-
toolbar : :class:`NavigationToolbar2`
2302+
toolbar : `NavigationToolbar2`
23212303
the navigation cursor toolbar
23222304
"""
23232305
# these bindings happen whether you are over an axes or not
@@ -2527,7 +2509,7 @@ class FigureManagerBase:
25272509
25282510
Attributes
25292511
----------
2530-
canvas : :class:`FigureCanvasBase`
2512+
canvas : `FigureCanvasBase`
25312513
The backend-specific canvas instance.
25322514
25332515
num : int or str

0 commit comments

Comments
 (0)