Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e7a4fc3

Browse files
committed
reply to comments
1 parent 16a3448 commit e7a4fc3

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

doc/users/interactive.rst

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ Matplotlib ships with :ref:`backends <what-is-a-backend>` binding to
1717
several GUI toolkits (Qt, Tk, Wx, GTK, macOS, JavaScript) and third party
1818
packages provide bindings to `kivy
1919
<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>`).
2323

2424
The `.pyplot` module provides functions for explicitly creating figures
2525
that include interactive tools, a toolbar, a tool-tip, and
2626
:ref:`key bindings <key-event-handling>`:
2727

28-
* `.pyplot.figure`
28+
`.pyplot.figure`
2929
Creates a new empty `.figure.Figure` or selects an existing figure
3030

31-
* `.pyplot.subplots`
31+
`.pyplot.subplots`
3232
Creates a new `.figure.Figure` and fills it with a grid of `.axes.Axes`
3333

3434
`.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
3838
appropriate.
3939

4040
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')``.
4444

4545

4646
For more discussion of Matplotlib's event system and integrated event loops, please read:
@@ -58,12 +58,14 @@ IPython integration
5858
===================
5959

6060
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:
6769

6870
.. highlight:: ipython
6971

@@ -98,7 +100,7 @@ If you wish to disable interactive modification of the plot:
98100

99101
In [6]: plt.ioff()
100102

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:
102104

103105
::
104106

@@ -139,19 +141,22 @@ Interactive mode controls:
139141

140142
- whether created figures are automatically shown
141143
- 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
143145

144146
If in interactive mode:
145147

146148
- newly created figures will be displayed immediately
147149
- 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
149151

150152
If not in interactive mode:
151153

152154
- 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
155160
the plot windows are closed
156161

157162

@@ -161,21 +166,21 @@ to display the windows on your screen. If you only want to run the
161166
GUI event loop for a fixed amount of time, you can use `.pyplot.pause`.
162167
This will block the progress of your code as if you had called
163168
`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.
166170

167171
The GUI event loop being integrated with your command prompt and
168172
the figures being in interactive mode are independent of each other.
169173
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.
171175
You will not be able to pan/zoom and the figure may not even render
172176
(the window might appear black, transparent, or as a snapshot of the
173177
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
175179
at the prompt, regardless of pyplot's "interactive mode".
176180

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.
179184

180185

181186
.. warning::
@@ -276,7 +281,7 @@ If you only need to use the classic notebook, you can use
276281

277282
%matplotlib notebook
278283

279-
which uses the `.backend_nbagg` backend which is installed by Matplotlib;
284+
which uses the `.backend_nbagg` backend provided by Matplotlib;
280285
however, nbagg does not work in Jupyter Lab.
281286

282287
GUIs + Jupyter

0 commit comments

Comments
 (0)