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

Skip to content

Commit 28be004

Browse files
authored
Merge pull request #15874 from timhoffm/doc-backend_bases
DOC: Cleanup backend_bases docs
2 parents b8eb4b2 + da630c4 commit 28be004

File tree

1 file changed

+69
-56
lines changed

1 file changed

+69
-56
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 69 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ def get_alpha(self):
764764
return self._alpha
765765

766766
def get_antialiased(self):
767-
"Return whether the object should try to do antialiased rendering."
767+
"""Return whether the object should try to do antialiased rendering."""
768768
return self._antialiased
769769

770770
def get_capstyle(self):
@@ -1434,7 +1434,7 @@ def __str__(self):
14341434

14351435
class PickEvent(Event):
14361436
"""
1437-
a pick event, fired when the user picks a location on the canvas
1437+
A pick event, fired when the user picks a location on the canvas
14381438
sufficiently close to an artist.
14391439
14401440
Attrs: all the :class:`Event` attributes plus
@@ -1455,7 +1455,9 @@ class PickEvent(Event):
14551455
14561456
Examples
14571457
--------
1458-
::
1458+
Bind a function ``on_pick()`` to pick events, that prints the coordinates
1459+
of the picked data point::
1460+
14591461
ax.plot(np.rand(100), 'o', picker=5) # 5 points tolerance
14601462
14611463
def on_pick(event):
@@ -1551,8 +1553,6 @@ class FigureCanvasBase:
15511553
"""
15521554
The canvas the figure renders into.
15531555
1554-
Public attributes
1555-
15561556
Attributes
15571557
----------
15581558
figure : `matplotlib.figure.Figure`
@@ -1643,7 +1643,7 @@ def _idle_draw_cntx(self):
16431643

16441644
def is_saving(self):
16451645
"""
1646-
Returns whether the renderer is in the process of saving
1646+
Return whether the renderer is in the process of saving
16471647
to a file, rather than rendering for an on-screen buffer.
16481648
"""
16491649
return self._is_saving
@@ -1711,8 +1711,10 @@ def key_release_event(self, key, guiEvent=None):
17111711

17121712
def pick_event(self, mouseevent, artist, **kwargs):
17131713
"""
1714+
Callback processing for pick events.
1715+
17141716
This method will be called by artists who are picked and will
1715-
fire off :class:`PickEvent` callbacks registered listeners
1717+
fire off :class:`PickEvent` callbacks registered listeners.
17161718
"""
17171719
s = 'pick_event'
17181720
event = PickEvent(s, self, mouseevent, artist,
@@ -1722,6 +1724,8 @@ def pick_event(self, mouseevent, artist, **kwargs):
17221724

17231725
def scroll_event(self, x, y, step, guiEvent=None):
17241726
"""
1727+
Callback processing for scroll events.
1728+
17251729
Backend derived classes should call this function on any
17261730
scroll wheel event. (*x*, *y*) are the canvas coords ((0, 0) is lower
17271731
left). button and key are as defined in MouseEvent.
@@ -1740,6 +1744,8 @@ def scroll_event(self, x, y, step, guiEvent=None):
17401744

17411745
def button_press_event(self, x, y, button, dblclick=False, guiEvent=None):
17421746
"""
1747+
Callback processing for mouse button press events.
1748+
17431749
Backend derived classes should call this function on any mouse
17441750
button press. (*x*, *y*) are the canvas coords ((0, 0) is lower left).
17451751
button and key are as defined in :class:`MouseEvent`.
@@ -1755,6 +1761,8 @@ def button_press_event(self, x, y, button, dblclick=False, guiEvent=None):
17551761

17561762
def button_release_event(self, x, y, button, guiEvent=None):
17571763
"""
1764+
Callback processing for mouse button release events.
1765+
17581766
Backend derived classes should call this function on any mouse
17591767
button release.
17601768
@@ -1777,6 +1785,8 @@ def button_release_event(self, x, y, button, guiEvent=None):
17771785

17781786
def motion_notify_event(self, x, y, guiEvent=None):
17791787
"""
1788+
Callback processing for mouse movement events.
1789+
17801790
Backend derived classes should call this function on any
17811791
motion-notify-event.
17821792
@@ -1800,8 +1810,10 @@ def motion_notify_event(self, x, y, guiEvent=None):
18001810

18011811
def leave_notify_event(self, guiEvent=None):
18021812
"""
1813+
Callback processing for the mouse cursor leaving the canvas.
1814+
18031815
Backend derived classes should call this function when leaving
1804-
canvas
1816+
canvas.
18051817
18061818
Parameters
18071819
----------
@@ -1814,8 +1826,10 @@ def leave_notify_event(self, guiEvent=None):
18141826

18151827
def enter_notify_event(self, guiEvent=None, xy=None):
18161828
"""
1829+
Callback processing for the mouse cursor entering the canvas.
1830+
18171831
Backend derived classes should call this function when entering
1818-
canvas
1832+
canvas.
18191833
18201834
Parameters
18211835
----------
@@ -1839,19 +1853,17 @@ def enter_notify_event(self, guiEvent=None, xy=None):
18391853

18401854
def inaxes(self, xy):
18411855
"""
1842-
Check if a point is in an axes.
1856+
Return the topmost `~.axes.Axes` containing the point *xy*.
18431857
18441858
Parameters
18451859
----------
1846-
xy : tuple or list
1847-
(x, y) coordinates.
1848-
x position - pixels from left of canvas.
1849-
y position - pixels from bottom of canvas.
1860+
xy : (float, float)
1861+
(x, y) pixel positions from left/bottom of the canvas.
18501862
18511863
Returns
18521864
-------
1853-
axes: topmost axes containing the point, or None if no axes.
1854-
1865+
axes : `~matplotlib.axes.Axes` or None
1866+
The topmost axes containing the point, or None if no axes.
18551867
"""
18561868
axes_list = [a for a in self.figure.get_axes()
18571869
if a.patch.contains_point(xy)]
@@ -1865,21 +1877,21 @@ def inaxes(self, xy):
18651877

18661878
def grab_mouse(self, ax):
18671879
"""
1868-
Set the child axes which are currently grabbing the mouse events.
1869-
Usually called by the widgets themselves.
1870-
It is an error to call this if the mouse is already grabbed by
1871-
another axes.
1880+
Set the child `~.axes.Axes` which is grabbing the mouse events.
1881+
1882+
Usually called by the widgets themselves. It is an error to call this
1883+
if the mouse is already grabbed by another axes.
18721884
"""
18731885
if self.mouse_grabber not in (None, ax):
18741886
raise RuntimeError("Another Axes already grabs mouse input")
18751887
self.mouse_grabber = ax
18761888

18771889
def release_mouse(self, ax):
18781890
"""
1879-
Release the mouse grab held by the axes, ax.
1880-
Usually called by the widgets.
1881-
It is ok to call this even if you ax doesn't have the mouse
1882-
grab currently.
1891+
Release the mouse grab held by the `~.axes.Axes` *ax*.
1892+
1893+
Usually called by the widgets. It is ok to call this even if *ax*
1894+
doesn't have the mouse grab currently.
18831895
"""
18841896
if self.mouse_grabber is ax:
18851897
self.mouse_grabber = None
@@ -1914,7 +1926,7 @@ def draw_cursor(self, event):
19141926
def get_width_height(self):
19151927
"""
19161928
Return the figure width and height in points or pixels
1917-
(depending on the backend), truncated to integers
1929+
(depending on the backend), truncated to integers.
19181930
"""
19191931
return int(self.figure.bbox.width), int(self.figure.bbox.height)
19201932

@@ -2110,16 +2122,18 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None,
21102122
@classmethod
21112123
def get_default_filetype(cls):
21122124
"""
2113-
Get the default savefig file format as specified in
2114-
:rc:`savefig.format`. Returned string excludes period. Overridden
2115-
in backends that only support a single file type.
2125+
Return the default savefig file format as specified in
2126+
:rc:`savefig.format`.
2127+
2128+
The returned string does not include a period. This method is
2129+
overridden in backends that only support a single file type.
21162130
"""
21172131
return rcParams['savefig.format']
21182132

21192133
def get_window_title(self):
21202134
"""
2121-
Get the title text of the window containing the figure.
2122-
Return None if there is no window (e.g., a PS backend).
2135+
Return the title text of the window containing the figure, or None
2136+
if there is no window (e.g., a PS backend).
21232137
"""
21242138
if self.manager:
21252139
return self.manager.get_window_title()
@@ -2594,9 +2608,8 @@ def button_press(self, event):
25942608

25952609
def get_window_title(self):
25962610
"""
2597-
Get the title text of the window containing the figure.
2598-
2599-
Return None for non-GUI (e.g., PS) backends.
2611+
Return the title text of the window containing the figure, or None
2612+
if there is no window (e.g., a PS backend).
26002613
"""
26012614
return 'image'
26022615

@@ -3154,15 +3167,15 @@ def __init__(self, toolmanager):
31543167

31553168
def _tool_toggled_cbk(self, event):
31563169
"""
3157-
Captures the 'tool_trigger_[name]'
3170+
Capture the 'tool_trigger_[name]'
31583171
3159-
This only gets used for toggled tools
3172+
This only gets used for toggled tools.
31603173
"""
31613174
self.toggle_toolitem(event.tool.name, event.tool.toggled)
31623175

31633176
def add_tool(self, tool, group, position=-1):
31643177
"""
3165-
Adds a tool to this container
3178+
Add a tool to this container.
31663179
31673180
Parameters
31683181
----------
@@ -3186,7 +3199,7 @@ def add_tool(self, tool, group, position=-1):
31863199
self.toggle_toolitem(tool.name, True)
31873200

31883201
def _remove_tool_cbk(self, event):
3189-
"""Captures the 'tool_removed_event' signal and removes the tool."""
3202+
"""Capture the 'tool_removed_event' signal and removes the tool."""
31903203
self.remove_toolitem(event.tool.name)
31913204

31923205
def _get_image_filename(self, image):
@@ -3206,7 +3219,7 @@ def _get_image_filename(self, image):
32063219

32073220
def trigger_tool(self, name):
32083221
"""
3209-
Trigger the tool
3222+
Trigger the tool.
32103223
32113224
Parameters
32123225
----------
@@ -3217,42 +3230,42 @@ def trigger_tool(self, name):
32173230

32183231
def add_toolitem(self, name, group, position, image, description, toggle):
32193232
"""
3220-
Add a toolitem to the container
3233+
Add a toolitem to the container.
32213234
3222-
This method must get implemented per backend
3235+
This method must be implemented per backend.
32233236
32243237
The callback associated with the button click event,
3225-
must be **EXACTLY** `self.trigger_tool(name)`
3238+
must be *exactly* ``self.trigger_tool(name)``.
32263239
32273240
Parameters
32283241
----------
32293242
name : str
32303243
Name of the tool to add, this gets used as the tool's ID and as the
3231-
default label of the buttons
3232-
group : String
3233-
Name of the group that this tool belongs to
3234-
position : Int
3235-
Position of the tool within its group, if -1 it goes at the End
3236-
image_file : String
3237-
Filename of the image for the button or `None`
3238-
description : String
3239-
Description of the tool, used for the tooltips
3240-
toggle : Bool
3244+
default label of the buttons.
3245+
group : str
3246+
Name of the group that this tool belongs to.
3247+
position : int
3248+
Position of the tool within its group, if -1 it goes at the end.
3249+
image_file : str
3250+
Filename of the image for the button or `None`.
3251+
description : str
3252+
Description of the tool, used for the tooltips.
3253+
toggle : bool
32413254
* `True` : The button is a toggle (change the pressed/unpressed
3242-
state between consecutive clicks)
3255+
state between consecutive clicks).
32433256
* `False` : The button is a normal button (returns to unpressed
3244-
state after release)
3257+
state after release).
32453258
"""
32463259
raise NotImplementedError
32473260

32483261
def toggle_toolitem(self, name, toggled):
32493262
"""
3250-
Toggle the toolitem without firing event
3263+
Toggle the toolitem without firing event.
32513264
32523265
Parameters
32533266
----------
3254-
name : String
3255-
Id of the tool to toggle
3267+
name : str
3268+
Id of the tool to toggle.
32563269
toggled : bool
32573270
Whether to set this tool as toggled or not.
32583271
"""

0 commit comments

Comments
 (0)