@@ -13,9 +13,9 @@ Axes to inspect your data is 'baked in' to Matplotlib. This is
13
13
supported by a full mouse and keyboard event handling system that
14
14
you can use to build sophisticated interactive graphs.
15
15
16
- This is meant to be an introduction to the low-level details of how
17
- integrating the Matplotlib with a GUI event loop works. For a more
18
- practical introduction the Matplotlib event API see :ref: `event
16
+ This guide is meant to be an introduction to the low-level details of
17
+ how Matplotlib integration with a GUI event loop works. For a more
18
+ practical introduction to the Matplotlib event API see :ref: `event
19
19
handling system <event-handling-tutorial>`, `Interactive Tutorial
20
20
<https://github.com/matplotlib/interactive_tutorial> `__, and
21
21
`Interactive Applications using Matplotlib
@@ -45,7 +45,7 @@ while the *Evaluate* and *Print* are responsible for interpreting the
45
45
input and then **doing ** something about it.
46
46
47
47
In practice we interact with a framework that provides a mechanism to
48
- register callbacks to be called in response to specific event rather
48
+ register callbacks to be run in response to specific events rather
49
49
than directly implement the I/O loop [#f2 ]_. For example "when the
50
50
user clicks on this button, please run this function" or "when the
51
51
user hits the 'z' key, please run this other function". This allows
@@ -60,10 +60,9 @@ All GUI frameworks (Qt, Wx, Gtk, tk, OSX, or web) have some method of
60
60
capturing user interactions and passing them back to the application
61
61
(for example ``Signal `` / ``Slot `` framework in Qt) but the exact
62
62
details depend on the toolkit. Matplotlib has a :ref: `backend
63
- <what-is-a-backend>` for each GUI toolkit we support which use the
64
- toolkit API to bridge the toolkit UI events into Matplotlib events
65
- into Matplotlib's :ref: `event handling system
66
- <event-handling-tutorial>`. You can then use
63
+ <what-is-a-backend>` for each GUI toolkit we support which uses the
64
+ toolkit API to bridge the toolkit UI events into Matplotlib's :ref: `event
65
+ handling system <event-handling-tutorial>`. You can then use
67
66
`.FigureCanvasBase.mpl_connect ` to connect your function to
68
67
Matplotlib's event handling system. This allows you to directly
69
68
interact with your data and write GUI toolkit agnostic user
@@ -77,8 +76,8 @@ Command Prompt Integration
77
76
78
77
So far, so good. We have the REPL (like the IPython terminal) that
79
78
lets us interactively send things code to the interpreter and get
80
- results back. We also have the GUI toolkit that run an event loop
81
- waiting for user input and let up register functions to be run when
79
+ results back. We also have the GUI toolkit that runs an event loop
80
+ waiting for user input and lets us register functions to be run when
82
81
that happens. However, if we want to do both we have a problem: the
83
82
prompt and the GUI event loop are both infinite loops that each think
84
83
*they * are in charge! In order for both the prompt and the GUI windows
@@ -148,7 +147,7 @@ able to have a usable prompt **and** interactive figure windows.
148
147
149
148
We can do this using the 'input hook' feature of the interactive
150
149
prompt. This hook is called by the prompt as it waits for the user
151
- type (even for a fast typist the prompt is mostly waiting for the
150
+ to type (even for a fast typist the prompt is mostly waiting for the
152
151
human to think and move their fingers). Although the details vary
153
152
between prompts the logic is roughly
154
153
@@ -157,7 +156,7 @@ between prompts the logic is roughly
157
156
3. as soon as the user hits a key, exit the GUI event loop and handle the key
158
157
4. repeat
159
158
160
- This gives us the illusion of simultaneously having an interactive GUI
159
+ This gives us the illusion of simultaneously having interactive GUI
161
160
windows and an interactive prompt. Most of the time the GUI event
162
161
loop is running, but as soon as the user starts typing the prompt
163
162
takes over again.
@@ -167,7 +166,7 @@ python is otherwise idle and waiting for user input. If you want the
167
166
GUI to be responsive during long running code it is necessary to
168
167
periodically flush the GUI event queue as described :ref: `above
169
168
<spin_event_loop>`. In this case it is your code, not the REPL, which
170
- is blocking process so you need to handle the "time-share" manually.
169
+ is blocking the process so you need to handle the "time-share" manually.
171
170
Conversely, a very slow figure draw will block the prompt until it
172
171
finishes drawing.
173
172
@@ -220,7 +219,7 @@ event loop using the methods described :ref:`above <cp_block_the_prompt>`.
220
219
221
220
You can also use the methods described in :ref: `cp_block_the_prompt `
222
221
to suspend run the GUI event loop. Once the loop exits your code will
223
- resume. In general, anyplace you would use `time.sleep ` you can use
222
+ resume. In general, any place you would use `time.sleep ` you can use
224
223
`.pyplot.pause ` instead with the added benefit of interactive figures.
225
224
226
225
For example, if you want to poll for data you could use something like ::
@@ -280,7 +279,7 @@ For example ::
280
279
slow_loop(100, ln)
281
280
282
281
While this will feel a bit laggy (as we are only processing user input
283
- every 100ms where as 20-30ms is what feels "responsive") it will
282
+ every 100ms whereas 20-30ms is what feels "responsive") it will
284
283
respond.
285
284
286
285
If you make changes to the plot and want it re-rendered you will need
@@ -304,7 +303,7 @@ We can add this our example above as ::
304
303
305
304
The more frequently you call `.FigureCanvasBase.flush_events ` the more
306
305
responsive your figure will feel but at the cost of spending more
307
- resource on the visualization and less on your computation.
306
+ resources on the visualization and less on your computation.
308
307
309
308
310
309
.. _stale_artists :
@@ -315,10 +314,10 @@ Stale Artists
315
314
Artists (as of Matplotlib 1.5) have a **stale ** attribute which is
316
315
`True ` if the internal state of the artist has changed since the last
317
316
time it was rendered. By default the stale state is propagated up to
318
- the Artists parents in the draw tree, thus if the color of a `.Line2D `
319
- instance is changed, the `.axes.Axes ` and `.figure.Figure ` it is
320
- contained in will also be marked as "stale". Thus, ``fig.stale `` will
321
- report of any artist in the figure has been modified and out of sync
317
+ the Artists parents in the draw tree, e.g., if the color of a `.Line2D `
318
+ instance is changed, the `.axes.Axes ` and `.figure.Figure ` that
319
+ contain it will also be marked as "stale". Thus, ``fig.stale `` will
320
+ report if any artist in the figure has been modified and is out of sync
322
321
with what is displayed on the screen. This is intended to be used to
323
322
determine if ``draw_idle `` should be called to schedule a re-rendering
324
323
of the figure.
@@ -330,17 +329,17 @@ with the signature ::
330
329
...
331
330
332
331
which by default is set to a function that forwards the stale state to
333
- the artists parent. If you wish to suppress a given artist from propagating
332
+ the artist's parent. If you wish to suppress a given artist from propagating
334
333
set this attribute to None.
335
334
336
335
`.figure.Figure ` instances do not have a containing artist and their
337
336
default callback is `None `. If you call `.pyplot.ion ` and are not in
338
- ``IPython `` we will install callback to invoke
339
- `~.backend_bases.FigureCanvasBase.draw_idle ` when ever the
337
+ ``IPython `` we will install a callback to invoke
338
+ `~.backend_bases.FigureCanvasBase.draw_idle ` whenever the
340
339
`.figure.Figure ` becomes stale. In ``IPython `` we use the
341
340
``'post_execute' `` hook to invoke
342
341
`~.backend_bases.FigureCanvasBase.draw_idle ` on any stale figures
343
- after having executed the users input, but before returning the prompt
342
+ after having executed the user's input, but before returning the prompt
344
343
to the user. If you are not using `.pyplot ` you can use the callback
345
344
`Figure.stale_callback ` attribute to be notified when a figure has
346
345
become stale.
@@ -363,7 +362,7 @@ Draw Idle
363
362
In almost all cases, we recommend using
364
363
`backend_bases.FigureCanvasBase.draw_idle ` over
365
364
`backend_bases.FigureCanvasBase.draw `. ``draw `` forces a rendering of
366
- the figure where as ``draw_idle `` schedules a rendering the next time
365
+ the figure whereas ``draw_idle `` schedules a rendering the next time
367
366
the GUI window is going to re-paint the screen. This improves
368
367
performance by only rendering pixels that will be shown on the screen. If
369
368
you want to be sure that the screen is updated as soon as possible do ::
@@ -448,7 +447,7 @@ method. The source for the prompt_toolkit input hooks lives at
448
447
.. [#f2 ] Or you can `write your own
449
448
<https://www.youtube.com/watch?v=ZzfHjytDceU> `__ if you must.
450
449
451
- .. [#f3 ] These examples are agressively dropping many of the
450
+ .. [#f3 ] These examples are aggressively dropping many of the
452
451
complexities that must be dealt with in the real world such as
453
- keyboard interupts , timeouts, bad input, resource
452
+ keyboard interrupts , timeouts, bad input, resource
454
453
allocation and cleanup, etc.
0 commit comments