Skip to content

Commit 34fa840

Browse files
authored
Merge pull request #15791 from anntzer/backend_bases-docs
Cleanup backend_bases docstrings.
2 parents 04acc1b + 84d1709 commit 34fa840

File tree

1 file changed

+64
-71
lines changed

1 file changed

+64
-71
lines changed

lib/matplotlib/backend_bases.py

+64-71
Original file line numberDiff line numberDiff line change
@@ -1035,29 +1035,23 @@ class TimerBase:
10351035
own timing mechanisms so that the timer events are integrated into their
10361036
event loops.
10371037
1038-
Mandatory functions that must be implemented:
1038+
Subclasses must override the following methods:
10391039
1040-
* `_timer_start`: Contains backend-specific code for starting
1041-
the timer
1040+
- ``_timer_start``: Backend-specific code for starting the timer.
1041+
- ``_timer_stop``: Backend-specific code for stopping the timer.
10421042
1043-
* `_timer_stop`: Contains backend-specific code for stopping
1044-
the timer
1043+
Subclasses may additionally override the following methods:
10451044
1046-
Optional overrides:
1045+
- ``_timer_set_single_shot``: Code for setting the timer to single shot
1046+
operating mode, if supported by the timer object. If not, the `Timer`
1047+
class itself will store the flag and the ``_on_timer`` method should be
1048+
overridden to support such behavior.
10471049
1048-
* `_timer_set_single_shot`: Code for setting the timer to
1049-
single shot operating mode, if supported by the timer
1050-
object. If not, the `Timer` class itself will store the flag
1051-
and the `_on_timer` method should be overridden to support
1052-
such behavior.
1050+
- ``_timer_set_interval``: Code for setting the interval on the timer, if
1051+
there is a method for doing so on the timer object.
10531052
1054-
* `_timer_set_interval`: Code for setting the interval on the
1055-
timer, if there is a method for doing so on the timer
1056-
object.
1057-
1058-
* `_on_timer`: This is the internal function that any timer
1059-
object should call, which will handle the task of running
1060-
all callbacks that have been set.
1053+
- ``_on_timer``: The internal function that any timer object should call,
1054+
which will handle the task of running all callbacks that have been set.
10611055
10621056
Attributes
10631057
----------
@@ -1414,8 +1408,7 @@ class MouseEvent(LocationEvent):
14141408
14151409
Examples
14161410
--------
1417-
Usage::
1418-
1411+
::
14191412
def on_press(event):
14201413
print('you pressed', event.button, event.xdata, event.ydata)
14211414
@@ -1466,8 +1459,7 @@ class PickEvent(Event):
14661459
14671460
Examples
14681461
--------
1469-
Usage::
1470-
1462+
::
14711463
ax.plot(np.rand(100), 'o', picker=5) # 5 points tolerance
14721464
14731465
def on_pick(event):
@@ -1477,7 +1469,6 @@ def on_pick(event):
14771469
print('on pick line:', np.array([xdata[ind], ydata[ind]]).T)
14781470
14791471
cid = fig.canvas.mpl_connect('pick_event', on_pick)
1480-
14811472
"""
14821473
def __init__(self, name, canvas, mouseevent, artist,
14831474
guiEvent=None, **kwargs):
@@ -1514,13 +1505,11 @@ class KeyEvent(LocationEvent):
15141505
15151506
Examples
15161507
--------
1517-
Usage::
1518-
1508+
::
15191509
def on_key(event):
15201510
print('you pressed', event.key, event.xdata, event.ydata)
15211511
15221512
cid = fig.canvas.mpl_connect('key_press_event', on_key)
1523-
15241513
"""
15251514
def __init__(self, name, canvas, key, x=0, y=0, guiEvent=None):
15261515
LocationEvent.__init__(self, name, canvas, x, y, guiEvent=guiEvent)
@@ -2173,44 +2162,50 @@ def switch_backends(self, FigureCanvasClass):
21732162

21742163
def mpl_connect(self, s, func):
21752164
"""
2176-
Connect event with string *s* to *func*. The signature of *func* is::
2177-
2178-
def func(event)
2179-
2180-
where event is a :class:`matplotlib.backend_bases.Event`. The
2181-
following events are recognized
2182-
2183-
- 'button_press_event'
2184-
- 'button_release_event'
2185-
- 'draw_event'
2186-
- 'key_press_event'
2187-
- 'key_release_event'
2188-
- 'motion_notify_event'
2189-
- 'pick_event'
2190-
- 'resize_event'
2191-
- 'scroll_event'
2192-
- 'figure_enter_event',
2193-
- 'figure_leave_event',
2194-
- 'axes_enter_event',
2195-
- 'axes_leave_event'
2196-
- 'close_event'
2197-
2198-
For the location events (button and key press/release), if the
2199-
mouse is over the axes, the variable ``event.inaxes`` will be
2200-
set to the :class:`~matplotlib.axes.Axes` the event occurs is
2201-
over, and additionally, the variables ``event.xdata`` and
2202-
``event.ydata`` will be defined. This is the mouse location
2203-
in data coords. See
2204-
:class:`~matplotlib.backend_bases.KeyEvent` and
2205-
:class:`~matplotlib.backend_bases.MouseEvent` for more info.
2206-
2207-
Return value is a connection id that can be used with
2208-
:meth:`~matplotlib.backend_bases.Event.mpl_disconnect`.
2165+
Bind function *func* to event *s*.
2166+
2167+
Parameters
2168+
----------
2169+
s : str
2170+
One of the following events ids:
2171+
2172+
- 'button_press_event'
2173+
- 'button_release_event'
2174+
- 'draw_event'
2175+
- 'key_press_event'
2176+
- 'key_release_event'
2177+
- 'motion_notify_event'
2178+
- 'pick_event'
2179+
- 'resize_event'
2180+
- 'scroll_event'
2181+
- 'figure_enter_event',
2182+
- 'figure_leave_event',
2183+
- 'axes_enter_event',
2184+
- 'axes_leave_event'
2185+
- 'close_event'.
2186+
2187+
func : callable
2188+
The callback function to be executed, which must have the
2189+
signature::
2190+
2191+
def func(event: Event) -> Any
2192+
2193+
For the location events (button and key press/release), if the
2194+
mouse is over the axes, the ``inaxes`` attribute of the event will
2195+
be set to the `~matplotlib.axes.Axes` the event occurs is over, and
2196+
additionally, the variables ``xdata`` and ``ydata`` attributes will
2197+
be set to the mouse location in data coordinates. See `.KeyEvent`
2198+
and `.MouseEvent` for more info.
2199+
2200+
Returns
2201+
-------
2202+
cid
2203+
A connection id that can be used with
2204+
`.FigureCanvasBase.mpl_disconnect`.
22092205
22102206
Examples
22112207
--------
2212-
Usage::
2213-
2208+
::
22142209
def on_press(event):
22152210
print('you pressed', event.button, event.xdata, event.ydata)
22162211
@@ -2221,24 +2216,23 @@ def on_press(event):
22212216

22222217
def mpl_disconnect(self, cid):
22232218
"""
2224-
Disconnect callback id cid
2219+
Disconnect the callback with id *cid*.
22252220
22262221
Examples
22272222
--------
2228-
Usage::
2229-
2223+
::
22302224
cid = canvas.mpl_connect('button_press_event', on_press)
2231-
#...later
2225+
# ... later
22322226
canvas.mpl_disconnect(cid)
22332227
"""
22342228
return self.callbacks.disconnect(cid)
22352229

22362230
def new_timer(self, *args, **kwargs):
22372231
"""
2238-
Creates a new backend-specific subclass of
2239-
:class:`backend_bases.Timer`. This is useful for getting periodic
2240-
events through the backend's native event loop. Implemented only for
2241-
backends with GUIs.
2232+
Create a new backend-specific subclass of `.Timer`.
2233+
2234+
This is useful for getting periodic events through the backend's native
2235+
event loop. Implemented only for backends with GUIs.
22422236
22432237
Other Parameters
22442238
----------------
@@ -2249,13 +2243,12 @@ def new_timer(self, *args, **kwargs):
22492243
Sequence of (func, args, kwargs) where ``func(*args, **kwargs)``
22502244
will be executed by the timer every *interval*.
22512245
2252-
callbacks which return ``False`` or ``0`` will be removed from the
2246+
Callbacks which return ``False`` or ``0`` will be removed from the
22532247
timer.
22542248
22552249
Examples
22562250
--------
22572251
>>> timer = fig.canvas.new_timer(callbacks=[(f1, (1, ), {'a': 3}),])
2258-
22592252
"""
22602253
return TimerBase(*args, **kwargs)
22612254

0 commit comments

Comments
 (0)