Skip to content

Commit 09deda3

Browse files
committed
DOC: re-arrange shell.rst and interactive.rst
DOC: minor tweaks to interactive docs
1 parent 6263284 commit 09deda3

File tree

2 files changed

+177
-6
lines changed

2 files changed

+177
-6
lines changed

doc/users/interactive.rst

Lines changed: 165 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,174 @@
1-
.. _dump-index:
1+
.. currentmodule:: matplotlib
22

3+
.. _mpl-shell:
34
===================
45
Interactive plots
56
===================
67

78
.. toctree::
89
:maxdepth: 2
910

10-
navigation_toolbar.rst
11-
shell.rst
12-
event_handling.rst
1311
interactive_guide
12+
event_handling.rst
13+
14+
15+
By default, matplotlib defers drawing until explicitly asked. Drawing
16+
can be an expensive operation, and you do not want to re-render the
17+
figure every time a single property is changed, only once after all
18+
the properties have changed and the figure is displayed on the screen
19+
or saved to disk. When working in a shell, one typically wants the
20+
figure to re-draw after every user command (ex when the prompt comes
21+
back). *interactive* mode of :mod:`~.pyplot` takes care of arranging
22+
such that if any open figures are :ref:`stale <stale_artists>`, they
23+
will be re-drawn just before the prompt is returned to the user.
24+
25+
.. _ipython-pylab:
26+
27+
IPython to the rescue
28+
=====================
29+
30+
We recommend using IPython for an interactive shell. In addition to
31+
all of it's features (improved tab-completion, magics,
32+
multiline-editing, etc), it also ensures that the GUI toolkit is
33+
properly integrated with the command line (see :ref:`cp_integration`).
34+
To configure the integration and enable interactive mode do::
35+
36+
.. sourcecode:: ipython
37+
38+
user@machine:~ $ ipython
39+
Python 3.6.4 (default, Dec 23 2017, 19:07:07)
40+
Type 'copyright', 'credits' or 'license' for more information
41+
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
42+
43+
In [1]: %matplotlib
44+
iUsing matplotlib backend: Qt5Agg
45+
46+
In [2]: import matplotlib.pyplot as plt
47+
48+
In [3]:
49+
50+
Calling
51+
52+
.. sourcecode:: ipython
53+
54+
In [3]: fig, ax = plt.subplots()
55+
56+
will pop open a window for you and
57+
58+
.. sourcecode:: ipython
59+
60+
In [4]: ln, = ax.plot(range(5))
61+
62+
will show your data in the window. If you
63+
want to change anything about the line, ex the color
64+
65+
.. sourcecode:: ipython
66+
67+
In [5]: ln.set_color('orange')
68+
69+
will be reflected immediately.
70+
71+
72+
73+
.. _other-shells:
74+
75+
Other python interpreters
76+
=========================
77+
78+
If you can not or do not want to use IPython, interactive mode
79+
should work in the vanilla python prompt
80+
81+
82+
.. sourcecode:: python
83+
84+
user@machine:~ $ python
85+
Python 3.6.4 (default, Dec 23 2017, 19:07:07)
86+
[GCC 7.2.1 20171128] on linux
87+
Type "help", "copyright", "credits" or "license" for more information.
88+
>>> import matplotlib.pyplot as plt
89+
>>> plt.ion()
90+
>>>
91+
92+
however this does not ensure that the event hook is properly installed
93+
and your figures may not be responsive (see :ref:`cp_integration`).
94+
95+
GUI python prompts may or may not work with all backends. For
96+
example, if you use the IDLE IDE you must use the 'tkagg' backend (as
97+
IDLE is a Tk application.. However, if you use spyder, the
98+
interactive shell is run in a sub process of the GUI and you can use
99+
any backend.
100+
101+
102+
.. _controlling-interactive:
103+
104+
Controlling interactive updating
105+
================================
106+
107+
108+
To control and query the current state of *interactive* mode
109+
110+
.. autosummary::
111+
:template: autosummary.rst
112+
:nosignatures:
113+
114+
pyplot.ion
115+
pyplot.ioff
116+
pyplot.isinteractive
117+
118+
When working with a big figure in which drawing is expensive, you may
119+
want to turn matplotlib's interactive setting off temporarily to avoid
120+
the performance hit::
121+
122+
123+
>>> #create big-expensive-figure
124+
>>> plt.ioff() # turn updates off
125+
>>> ax.set_title('now how much would you pay?')
126+
>>> fig.canvas.draw_idle() # force a draw
127+
>>> fig.savefig('alldone', dpi=300)
128+
>>> plt.close('all')
129+
>>> plt.ion() # turn updating back on
130+
>>> fig, ax = plt.subplots()
131+
>>> ax.plot(rand(20), mfc='g', mec='r', ms=40, mew=4, ls='--', lw=3)
132+
133+
134+
Default UI
135+
==========
136+
137+
138+
.. toctree::
139+
:maxdepth: 1
140+
141+
navigation_toolbar.rst
142+
143+
144+
The windows created by :mod:`~.pyplot` have an interactive toolbar and
145+
has a number of helpful keybindings by default.
146+
147+
.. _key-event-handling:
148+
149+
Navigation Keyboard Shortcuts
150+
-----------------------------
151+
152+
The following table holds all the default keys, which can be
153+
overwritten by use of your matplotlibrc (#keymap.\*).
154+
155+
================================== =================================================
156+
Command Keyboard Shortcut(s)
157+
================================== =================================================
158+
Home/Reset **h** or **r** or **home**
159+
Back **c** or **left arrow** or **backspace**
160+
Forward **v** or **right arrow**
161+
Pan/Zoom **p**
162+
Zoom-to-rect **o**
163+
Save **ctrl** + **s**
164+
Toggle fullscreen **f** or **ctrl** + **f**
165+
Close plot **ctrl** + **w**
166+
Close all plots **shift** + **w**
167+
Constrain pan/zoom to x axis hold **x** when panning/zooming with mouse
168+
Constrain pan/zoom to y axis hold **y** when panning/zooming with mouse
169+
Preserve aspect ratio hold **CONTROL** when panning/zooming with mouse
170+
Toggle major grids **g** when mouse is over an axes
171+
Toggle minor grids **G** when mouse is over an axes
172+
Toggle x axis scale (log/linear) **L** or **k** when mouse is over an axes
173+
Toggle y axis scale (log/linear) **l** when mouse is over an axes
174+
================================== =================================================

doc/users/interactive_guide.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ references to trackdown:
6161
- curio / trio / asycio / twisted / tornado event loops
6262
- Beazly talk or two on asyncio
6363

64+
65+
66+
Interactive Mode
67+
================
68+
69+
.. _cp_integration:
70+
6471
Command Prompt Integration
6572
==========================
6673

@@ -198,6 +205,8 @@ The third case you will have to integrate updating the ``Aritist``
198205
instances, calling ``draw_idle``, and the GUI event loop with your
199206
data I/O.
200207

208+
.. _stale_artists:
209+
201210
Stale Artists
202211
=============
203212

@@ -210,9 +219,10 @@ displayed on the screen. This is intended to be used to determine if
210219
``draw_idle`` should be called to schedule a re-rendering of the
211220
figure.
212221

222+
TODO:
213223

214-
Interactive Mode
215-
================
224+
- notes about callbacks
225+
-
216226

217227

218228
Draw Idle

0 commit comments

Comments
 (0)