@@ -1040,29 +1040,23 @@ class TimerBase:
1040
1040
own timing mechanisms so that the timer events are integrated into their
1041
1041
event loops.
1042
1042
1043
- Mandatory functions that must be implemented :
1043
+ Subclasses must override the following methods :
1044
1044
1045
- * ` _timer_start`: Contains backend -specific code for starting
1046
- the timer
1045
+ - `` _timer_start``: Backend -specific code for starting the timer.
1046
+ - ``_timer_stop``: Backend-specific code for stopping the timer.
1047
1047
1048
- * `_timer_stop`: Contains backend-specific code for stopping
1049
- the timer
1048
+ Subclasses may additionally override the following methods:
1050
1049
1051
- Optional overrides:
1050
+ - ``_timer_set_single_shot``: Code for setting the timer to single shot
1051
+ operating mode, if supported by the timer object. If not, the `Timer`
1052
+ class itself will store the flag and the ``_on_timer`` method should be
1053
+ overridden to support such behavior.
1052
1054
1053
- * `_timer_set_single_shot`: Code for setting the timer to
1054
- single shot operating mode, if supported by the timer
1055
- object. If not, the `Timer` class itself will store the flag
1056
- and the `_on_timer` method should be overridden to support
1057
- such behavior.
1055
+ - ``_timer_set_interval``: Code for setting the interval on the timer, if
1056
+ there is a method for doing so on the timer object.
1058
1057
1059
- * `_timer_set_interval`: Code for setting the interval on the
1060
- timer, if there is a method for doing so on the timer
1061
- object.
1062
-
1063
- * `_on_timer`: This is the internal function that any timer
1064
- object should call, which will handle the task of running
1065
- all callbacks that have been set.
1058
+ - ``_on_timer``: The internal function that any timer object should call,
1059
+ which will handle the task of running all callbacks that have been set.
1066
1060
1067
1061
Attributes
1068
1062
----------
@@ -1419,8 +1413,7 @@ class MouseEvent(LocationEvent):
1419
1413
1420
1414
Examples
1421
1415
--------
1422
- Usage::
1423
-
1416
+ ::
1424
1417
def on_press(event):
1425
1418
print('you pressed', event.button, event.xdata, event.ydata)
1426
1419
@@ -1471,8 +1464,7 @@ class PickEvent(Event):
1471
1464
1472
1465
Examples
1473
1466
--------
1474
- Usage::
1475
-
1467
+ ::
1476
1468
ax.plot(np.rand(100), 'o', picker=5) # 5 points tolerance
1477
1469
1478
1470
def on_pick(event):
@@ -1482,7 +1474,6 @@ def on_pick(event):
1482
1474
print('on pick line:', np.array([xdata[ind], ydata[ind]]).T)
1483
1475
1484
1476
cid = fig.canvas.mpl_connect('pick_event', on_pick)
1485
-
1486
1477
"""
1487
1478
def __init__ (self , name , canvas , mouseevent , artist ,
1488
1479
guiEvent = None , ** kwargs ):
@@ -1519,13 +1510,11 @@ class KeyEvent(LocationEvent):
1519
1510
1520
1511
Examples
1521
1512
--------
1522
- Usage::
1523
-
1513
+ ::
1524
1514
def on_key(event):
1525
1515
print('you pressed', event.key, event.xdata, event.ydata)
1526
1516
1527
1517
cid = fig.canvas.mpl_connect('key_press_event', on_key)
1528
-
1529
1518
"""
1530
1519
def __init__ (self , name , canvas , key , x = 0 , y = 0 , guiEvent = None ):
1531
1520
LocationEvent .__init__ (self , name , canvas , x , y , guiEvent = guiEvent )
@@ -2164,44 +2153,50 @@ def switch_backends(self, FigureCanvasClass):
2164
2153
2165
2154
def mpl_connect (self , s , func ):
2166
2155
"""
2167
- Connect event with string *s* to *func*. The signature of *func* is::
2168
-
2169
- def func(event)
2170
-
2171
- where event is a :class:`matplotlib.backend_bases.Event`. The
2172
- following events are recognized
2173
-
2174
- - 'button_press_event'
2175
- - 'button_release_event'
2176
- - 'draw_event'
2177
- - 'key_press_event'
2178
- - 'key_release_event'
2179
- - 'motion_notify_event'
2180
- - 'pick_event'
2181
- - 'resize_event'
2182
- - 'scroll_event'
2183
- - 'figure_enter_event',
2184
- - 'figure_leave_event',
2185
- - 'axes_enter_event',
2186
- - 'axes_leave_event'
2187
- - 'close_event'
2188
-
2189
- For the location events (button and key press/release), if the
2190
- mouse is over the axes, the variable ``event.inaxes`` will be
2191
- set to the :class:`~matplotlib.axes.Axes` the event occurs is
2192
- over, and additionally, the variables ``event.xdata`` and
2193
- ``event.ydata`` will be defined. This is the mouse location
2194
- in data coords. See
2195
- :class:`~matplotlib.backend_bases.KeyEvent` and
2196
- :class:`~matplotlib.backend_bases.MouseEvent` for more info.
2197
-
2198
- Return value is a connection id that can be used with
2199
- :meth:`~matplotlib.backend_bases.Event.mpl_disconnect`.
2156
+ Bind function *func* to event *s*.
2157
+
2158
+ Parameters
2159
+ ----------
2160
+ s : str
2161
+ One of the following events ids:
2162
+
2163
+ - 'button_press_event'
2164
+ - 'button_release_event'
2165
+ - 'draw_event'
2166
+ - 'key_press_event'
2167
+ - 'key_release_event'
2168
+ - 'motion_notify_event'
2169
+ - 'pick_event'
2170
+ - 'resize_event'
2171
+ - 'scroll_event'
2172
+ - 'figure_enter_event',
2173
+ - 'figure_leave_event',
2174
+ - 'axes_enter_event',
2175
+ - 'axes_leave_event'
2176
+ - 'close_event'.
2177
+
2178
+ func : callable
2179
+ The callback function to be executed, which must have the
2180
+ signature::
2181
+
2182
+ def func(event: Event) -> Any
2183
+
2184
+ For the location events (button and key press/release), if the
2185
+ mouse is over the axes, the ``inaxes`` attribute of the event will
2186
+ be set to the `~matplotlib.axes.Axes` the event occurs is over, and
2187
+ additionally, the variables ``xdata`` and ``ydata`` attributes will
2188
+ be set to the mouse location in data coordinates. See `.KeyEvent`
2189
+ and `.MouseEvent` for more info.
2190
+
2191
+ Returns
2192
+ -------
2193
+ cid
2194
+ A connection id that can be used with
2195
+ `.FigureCanvasBase.mpl_disconnect`.
2200
2196
2201
2197
Examples
2202
2198
--------
2203
- Usage::
2204
-
2199
+ ::
2205
2200
def on_press(event):
2206
2201
print('you pressed', event.button, event.xdata, event.ydata)
2207
2202
@@ -2212,24 +2207,23 @@ def on_press(event):
2212
2207
2213
2208
def mpl_disconnect (self , cid ):
2214
2209
"""
2215
- Disconnect callback id cid
2210
+ Disconnect the callback with id * cid*.
2216
2211
2217
2212
Examples
2218
2213
--------
2219
- Usage::
2220
-
2214
+ ::
2221
2215
cid = canvas.mpl_connect('button_press_event', on_press)
2222
- #...later
2216
+ # ... later
2223
2217
canvas.mpl_disconnect(cid)
2224
2218
"""
2225
2219
return self .callbacks .disconnect (cid )
2226
2220
2227
2221
def new_timer (self , * args , ** kwargs ):
2228
2222
"""
2229
- Creates a new backend-specific subclass of
2230
- :class:`backend_bases.Timer`. This is useful for getting periodic
2231
- events through the backend's native event loop. Implemented only for
2232
- backends with GUIs.
2223
+ Create a new backend-specific subclass of `.Timer`.
2224
+
2225
+ This is useful for getting periodic events through the backend's native
2226
+ event loop. Implemented only for backends with GUIs.
2233
2227
2234
2228
Other Parameters
2235
2229
----------------
@@ -2240,13 +2234,12 @@ def new_timer(self, *args, **kwargs):
2240
2234
Sequence of (func, args, kwargs) where ``func(*args, **kwargs)``
2241
2235
will be executed by the timer every *interval*.
2242
2236
2243
- callbacks which return ``False`` or ``0`` will be removed from the
2237
+ Callbacks which return ``False`` or ``0`` will be removed from the
2244
2238
timer.
2245
2239
2246
2240
Examples
2247
2241
--------
2248
2242
>>> timer = fig.canvas.new_timer(callbacks=[(f1, (1, ), {'a': 3}),])
2249
-
2250
2243
"""
2251
2244
return TimerBase (* args , ** kwargs )
2252
2245
0 commit comments