@@ -1035,29 +1035,23 @@ class TimerBase:
1035
1035
own timing mechanisms so that the timer events are integrated into their
1036
1036
event loops.
1037
1037
1038
- Mandatory functions that must be implemented :
1038
+ Subclasses must override the following methods :
1039
1039
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.
1042
1042
1043
- * `_timer_stop`: Contains backend-specific code for stopping
1044
- the timer
1043
+ Subclasses may additionally override the following methods:
1045
1044
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.
1047
1049
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.
1053
1052
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.
1061
1055
1062
1056
Attributes
1063
1057
----------
@@ -1414,8 +1408,7 @@ class MouseEvent(LocationEvent):
1414
1408
1415
1409
Examples
1416
1410
--------
1417
- Usage::
1418
-
1411
+ ::
1419
1412
def on_press(event):
1420
1413
print('you pressed', event.button, event.xdata, event.ydata)
1421
1414
@@ -1466,8 +1459,7 @@ class PickEvent(Event):
1466
1459
1467
1460
Examples
1468
1461
--------
1469
- Usage::
1470
-
1462
+ ::
1471
1463
ax.plot(np.rand(100), 'o', picker=5) # 5 points tolerance
1472
1464
1473
1465
def on_pick(event):
@@ -1477,7 +1469,6 @@ def on_pick(event):
1477
1469
print('on pick line:', np.array([xdata[ind], ydata[ind]]).T)
1478
1470
1479
1471
cid = fig.canvas.mpl_connect('pick_event', on_pick)
1480
-
1481
1472
"""
1482
1473
def __init__ (self , name , canvas , mouseevent , artist ,
1483
1474
guiEvent = None , ** kwargs ):
@@ -1514,13 +1505,11 @@ class KeyEvent(LocationEvent):
1514
1505
1515
1506
Examples
1516
1507
--------
1517
- Usage::
1518
-
1508
+ ::
1519
1509
def on_key(event):
1520
1510
print('you pressed', event.key, event.xdata, event.ydata)
1521
1511
1522
1512
cid = fig.canvas.mpl_connect('key_press_event', on_key)
1523
-
1524
1513
"""
1525
1514
def __init__ (self , name , canvas , key , x = 0 , y = 0 , guiEvent = None ):
1526
1515
LocationEvent .__init__ (self , name , canvas , x , y , guiEvent = guiEvent )
@@ -2173,44 +2162,47 @@ def switch_backends(self, FigureCanvasClass):
2173
2162
2174
2163
def mpl_connect (self , s , func ):
2175
2164
"""
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
+ Connect event string *s* to *func*.
2166
+
2167
+ Parameters
2168
+ ----------
2169
+ s : str
2170
+ One of the following events strings:
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
+ A callable taking a single parameter, which is an `.Event`.
2189
+
2190
+ For the location events (button and key press/release), if the
2191
+ mouse is over the axes, the ``inaxes`` attribute of the event will
2192
+ be set to the `~matplotlib.axes.Axes` the event occurs is over, and
2193
+ additionally, the variables ``xdata`` and ``ydata`` attributes will
2194
+ be set to the mouse location in data coordinates. See `.KeyEvent`
2195
+ and `.MouseEvent` for more info.
2196
+
2197
+ Returns
2198
+ -------
2199
+ cid
2200
+ A connection id that can be used with
2201
+ `.FigureCanvasBase.mpl_disconnect`.
2209
2202
2210
2203
Examples
2211
2204
--------
2212
- Usage::
2213
-
2205
+ ::
2214
2206
def on_press(event):
2215
2207
print('you pressed', event.button, event.xdata, event.ydata)
2216
2208
@@ -2221,24 +2213,22 @@ def on_press(event):
2221
2213
2222
2214
def mpl_disconnect (self , cid ):
2223
2215
"""
2224
- Disconnect callback id cid
2216
+ Disconnect the callback with id * cid*.
2225
2217
2226
2218
Examples
2227
2219
--------
2228
- Usage::
2229
-
2220
+ ::
2230
2221
cid = canvas.mpl_connect('button_press_event', on_press)
2231
- #...later
2222
+ # ... later
2232
2223
canvas.mpl_disconnect(cid)
2233
2224
"""
2234
2225
return self .callbacks .disconnect (cid )
2235
2226
2236
2227
def new_timer (self , * args , ** kwargs ):
2237
2228
"""
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.
2229
+ Creates a new backend-specific subclass of `.Timer`. This is useful
2230
+ for getting periodic events through the backend's native event
2231
+ loop. Implemented only for backends with GUIs.
2242
2232
2243
2233
Other Parameters
2244
2234
----------------
@@ -2249,13 +2239,12 @@ def new_timer(self, *args, **kwargs):
2249
2239
Sequence of (func, args, kwargs) where ``func(*args, **kwargs)``
2250
2240
will be executed by the timer every *interval*.
2251
2241
2252
- callbacks which return ``False`` or ``0`` will be removed from the
2242
+ Callbacks which return ``False`` or ``0`` will be removed from the
2253
2243
timer.
2254
2244
2255
2245
Examples
2256
2246
--------
2257
2247
>>> timer = fig.canvas.new_timer(callbacks=[(f1, (1, ), {'a': 3}),])
2258
-
2259
2248
"""
2260
2249
return TimerBase (* args , ** kwargs )
2261
2250
0 commit comments