@@ -17,18 +17,18 @@ Matplotlib ships with :ref:`backends <what-is-a-backend>` binding to
17
17
several GUI toolkits (Qt, Tk, Wx, GTK, macOS, JavaScript) and third party
18
18
packages provide bindings to `kivy
19
19
<https://github.com/kivy-garden/garden.matplotlib> `__ and `Jupyter Lab
20
- <https://github.com/matplotlib/ipympl> `__. For the figures to be interactive,
21
- the GUI event loop will need to be integrated with your interactive prompt.
22
- We recommend using IPython (see :ref: `below <ipython-pylab >`).
20
+ <https://github.com/matplotlib/ipympl> `__. For the figures to be responsive to
21
+ mouse, keyboard, and critical paint events, the GUI event loop needs to be integrated
22
+ with an interactive prompt. We recommend using IPython (see :ref: `below <ipython-pylab >`).
23
23
24
24
The `.pyplot ` module provides functions for explicitly creating figures
25
25
that include interactive tools, a toolbar, a tool-tip, and
26
26
:ref: `key bindings <key-event-handling >`:
27
27
28
- * `.pyplot.figure `
28
+ `.pyplot.figure `
29
29
Creates a new empty `.figure.Figure ` or selects an existing figure
30
30
31
- * `.pyplot.subplots `
31
+ `.pyplot.subplots `
32
32
Creates a new `.figure.Figure ` and fills it with a grid of `.axes.Axes `
33
33
34
34
`.pyplot ` has a notion of "The Current Figure" which can be accessed
@@ -38,9 +38,9 @@ through the current `.Figure` / `.axes.Axes` (or create one) as
38
38
appropriate.
39
39
40
40
Matplotlib keeps a reference to all of the open figures
41
- created this way so they will not be garbage collected. You can close
42
- and deregister `.Figure `\s from `.pyplot ` individually via
43
- `.pyplot.close ` or close all open figures via ``plt.close('all') ``.
41
+ created via ` pyplot.figure ` or ` pyplot.subplots ` so that the figures will not be garbage
42
+ collected. `.Figure `\s can be closed and deregistered from `.pyplot ` individually via
43
+ `.pyplot.close `; all open ` .Figure ` \s can be closed via ``plt.close('all') ``.
44
44
45
45
46
46
For more discussion of Matplotlib's event system and integrated event loops, please read:
@@ -58,12 +58,14 @@ IPython integration
58
58
===================
59
59
60
60
We recommend using IPython for an interactive shell. In addition to
61
- all of its features (improved tab-completion, magics,
62
- multiline editing, etc), it also ensures that the GUI toolkit event
63
- loop is properly integrated with the command line (see
64
- :ref: `cp_integration `). To configure the integration and enable
65
- :ref: `interactive mode <controlling-interactive >` use the
66
- ``%matplotlib `` magic
61
+ all of its features (improved tab-completion, magics, multiline editing, etc),
62
+ it also ensures that the GUI toolkit event loop is properly integrated
63
+ with the command line (see :ref: `cp_integration `).
64
+
65
+ In this example, we are modifying a figure via an IPython prompt.
66
+ The figure is displayed in a `Qt5Agg ` GUI Window. To configure the integration
67
+ and enable :ref: `interactive mode <controlling-interactive >` use the
68
+ ``%matplotlib `` magic:
67
69
68
70
.. highlight :: ipython
69
71
@@ -98,7 +100,7 @@ If you wish to disable interactive modification of the plot:
98
100
99
101
In [6]: plt.ioff()
100
102
101
- If you wish to re-enable interactive "live" modification of the plot:
103
+ If you wish to re-enable interactive modification of the plot:
102
104
103
105
::
104
106
@@ -139,19 +141,22 @@ Interactive mode controls:
139
141
140
142
- whether created figures are automatically shown
141
143
- whether changes to artists automatically trigger re-drawing existing figures
142
- - when `.pyplot.show ` exits : immediately, or after all of the figures have been closed if given no arguments
144
+ - when `.pyplot.show() ` returns : immediately, or after all of the figures have been closed when given no arguments
143
145
144
146
If in interactive mode:
145
147
146
148
- newly created figures will be displayed immediately
147
149
- figures will automatically redraw when elements are changed
148
- - `pyplot.show ` displays the figures and immediately returns to the prompt
150
+ - `pyplot.show() ` displays the figures and immediately returns
149
151
150
152
If not in interactive mode:
151
153
152
154
- newly created figures and changes to figures are not displayed until
153
- `.pyplot.show ` is called again or `.pyplot.pause ` exits
154
- - `pyplot.show ` runs the GUI event loop and does not return until all
155
+ * `.pyplot.show() ` returns and is called again
156
+ * `.pyplot.pause() ` returns
157
+ * ` fig.canvas.flush_events` is called
158
+
159
+ - `pyplot.show() ` runs the GUI event loop and does not return until all
155
160
the plot windows are closed
156
161
157
162
@@ -161,21 +166,21 @@ to display the windows on your screen. If you only want to run the
161
166
GUI event loop for a fixed amount of time, you can use `.pyplot.pause `.
162
167
This will block the progress of your code as if you had called
163
168
`time.sleep `, ensure the current window is shown and re-drawn if needed,
164
- and run the GUI event loop (so the windows are "live" for
165
- interactive modification) for the specified period of time.
169
+ and run the GUI event loop for the specified period of time.
166
170
167
171
The GUI event loop being integrated with your command prompt and
168
172
the figures being in interactive mode are independent of each other.
169
173
If you use `pyplot.ion ` but have not arranged for the event loop integration,
170
- your figures will appear but will not be "live" while the prompt is waiting for input.
174
+ your figures will appear but will not be interactive while the prompt is waiting for input.
171
175
You will not be able to pan/zoom and the figure may not even render
172
176
(the window might appear black, transparent, or as a snapshot of the
173
177
desktop under it). Conversely, if you configure the event loop
174
- integration, displayed figures will be "live" while waiting for input
178
+ integration, displayed figures will be responsive while waiting for input
175
179
at the prompt, regardless of pyplot's "interactive mode".
176
180
177
- The figures will also be "live" if you use ``pyplot.show(block=True) ``,
178
- `.pyplot.pause `, or run the the GUI main loop in some other way.
181
+ No matter what combination of interactive mode setting and event loop integration,
182
+ figures will be responsive if you use ``pyplot.show(block=True) ``, `.pyplot.pause `, or run
183
+ the GUI main loop in some other way.
179
184
180
185
181
186
.. warning ::
@@ -276,7 +281,7 @@ If you only need to use the classic notebook, you can use
276
281
277
282
%matplotlib notebook
278
283
279
- which uses the `.backend_nbagg ` backend which is installed by Matplotlib;
284
+ which uses the `.backend_nbagg ` backend provided by Matplotlib;
280
285
however, nbagg does not work in Jupyter Lab.
281
286
282
287
GUIs + Jupyter
0 commit comments