Skip to content

DOC: Start to document interactive figures #4779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
May 21, 2020
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cfa717a
DOC: Start to document interactive figures
tacaswell Jul 24, 2015
206f99c
DOC: improve text
tacaswell Jul 31, 2015
fa36c95
DOC: address comments
tacaswell Jan 7, 2017
8b28c01
DOC/WIP: updates to docs on how event loops work
tacaswell Jul 28, 2017
7189eed
DOC: add blocking_input docs
tacaswell Dec 28, 2017
98ae26c
WIP: Lots of text changes to interactive guide
tacaswell Dec 28, 2017
6263284
MNT: add warnings to Figure.show
tacaswell Dec 29, 2017
09deda3
DOC: re-arrange shell.rst and interactive.rst
tacaswell Jan 3, 2018
ec4230a
DOC/WIP: more edits and content
tacaswell Jul 10, 2018
d1a7a3e
WIP: more notes
tacaswell Mar 2, 2019
b49973a
DOC: merge the blocking API docs together
tacaswell Apr 28, 2020
bb8058a
DOC: remove rst files that have been merged into interactive.rst
tacaswell Apr 28, 2020
bc4ecd5
DOC: fix and sort intersphinx
tacaswell Apr 28, 2020
49f49fa
DOC: re-write pyplot.show docstring
tacaswell Apr 29, 2020
295d71d
DOC: plt.pause is no longer experimental
tacaswell Apr 29, 2020
c3c5013
DOC: update pyplot documentation
tacaswell Apr 30, 2020
d9df057
DOC: Lots of editing to interactive figure documentation
tacaswell Apr 30, 2020
7b0b327
DOC: it's -> its
tacaswell Apr 30, 2020
5a426d6
DOC: spelling
tacaswell Apr 30, 2020
8ab0a65
DOC: edits from review
tacaswell May 1, 2020
d70d5ad
DOC: update skipped references
tacaswell May 1, 2020
757e040
DOC: correct many spelling / grammer / clarity issues
tacaswell May 3, 2020
b0690ff
DOC: remove badly named and superfluous heading
tacaswell May 7, 2020
cc3ac5b
DOC: address review comments
tacaswell May 7, 2020
afe9edd
DOC: edits from review
tacaswell May 7, 2020
e09cab9
DOC: more small edits
tacaswell May 7, 2020
04f2fc6
DOC: fix spyder spelling
tacaswell May 7, 2020
9d842bf
DOC: edits from review
tacaswell May 7, 2020
41e19a8
MNT: remove unused import
tacaswell May 7, 2020
eda2ed3
DOC: edits from review
tacaswell May 9, 2020
7cf68e8
DOC: remove non-existent function call
tacaswell May 9, 2020
bfa3589
DOC: edits and duplicate removal
tacaswell May 9, 2020
6edcb47
DOC: windows not widows
tacaswell May 9, 2020
9b492bd
DOC: Revert all changes to blocking_input_api.rst
tacaswell May 9, 2020
6d4747f
DOC: reduce jargon and correct grammar
tacaswell May 20, 2020
f05ea3d
DOC: grammar / wording corrections from review
tacaswell May 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
DOC: improve text
  • Loading branch information
tacaswell committed May 1, 2020
commit 206f99cc36aa74768c4b98e73e5e0541c1adcd34
54 changes: 29 additions & 25 deletions doc/users/interactive_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Interactive Figures
*******************

One of the most powerful ways to use matplotlib is interactive
One of the most powerful uses of matplotlib is interactive
figures. At the most basic matplotlib has the ability to zoom and pan
a figure to inspect your data, however there is also a full mouse and
keyboard event handling system to enable building sophisticated interactive
Expand Down Expand Up @@ -34,30 +34,34 @@ requires option 2.
The python capi provides a hook, `PyOS_InputHook`, to register a
function to be run "The function will be called when Python's
interpreter prompt is about to become idle and wait for user input
from the terminal.". As an implementation detail of cpython when
using readline this times out every 0.1 seconds. Using this hook a
second event loop can be integrated with the terminal. This is done
in the cpython source for tk, by some GUI framework code (such as
pyqt), and by IPython. These function typically either exhaust all
pending events on the GUI event queue or run the main loop for a short
fixed amount of time. matplotlib does not currently do any management
of `PyOS_InputHook` due to the wide range of use-cases, this
management is left to the code using matplotlib. Due to this,
interactive figures, even with matplotlib in 'interactive mode' may
not be reliable in the vanilla python repl, we suggest using IPython
which ensures that such a function is registered for you GUI backend
of choice.

A draw back of the above approach is that in is only useful while
python is otherwise idle and waiting for user input. The exact
methods required to force the GUI to process it's event loop varies
between frameworks. To enable writing GUI agnostic code, almost all
of the GUI-based ``Canvas`` classes provide a `flush_event` method.
By periodically calling this method the GUI can appear to be
updated and appear to be responsive.

In both cases, scheduling a re-draw of the figure at some point in the
future use ``fig.canvas.draw_idle()``. This will defer the actual
from the terminal.". This hook can be used to integrate a second
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "second event loop"? What would be the first event loop?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The python prompt itself.

event loop with the python repl. Such a hooks are usually included
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such a hooks

with the python bindings for GUI toolkits and may be registered on
import. IPython also includes hooks for all of the GUI frameworks
supported by matplotlib. The hook functions typically exhaust
all pending events on the GUI event queue, run the main loop for a
short fixed amount of time, or run the event loop until a key is
pressed on stdin.

matplotlib does not currently do any management of `PyOS_InputHook`
due to the wide range of ways that matplotlib is used. This
management is left to the code using matplotlib. Interactive figures,
even with matplotlib in 'interactive mode', may not work in the
vanilla python repl if an appropriate `PyOS_InputHook` is not
registered. We suggest using ``IPython``, which in addition to
improving the command line, ensures that such a `PyOS_InptuHook`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(sp)

function is registered for you GUI backend of choice.

A drawback of relying on `PyOS_InputHook` is that the GUI event loop
is only processing events while python is otherwise idle and waiting
for user input. If you want the GUI to be responsive during long
running code it is necessary to periodically flush the GUI event
queue. To achive this, almost all of the of the GUI-based ``Canvas``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

achive --> achieve

classes provide a `flush_event` method. By periodically calling this
method the GUI will be updated and appear to be responsive.

In both cases, to schedule a re-draw of the figure at some point in
the future use ``fig.canvas.draw_idle()``. This will defer the actual
rendering of the figure until the GUI is ready to update it's
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's -> its

on-screen representation.

Expand Down