When working with data, interactivity can be invaluable. The pan/zoom andmouse-location tools built into the Matplotlib GUI windows are often sufficient, butyou can also use the event system to build customized data exploration tools.
Matplotlib ships with backends binding toseveral GUI toolkits (Qt, Tk, Wx, GTK, macOS, JavaScript) and third partypackages provide bindings to kivy and Jupyter Lab. For the figures to be responsive tomouse, keyboard, and paint events, the GUI event loop needs to be integratedwith an interactive prompt. We recommend using IPython (see below).
The pyplot
module provides functions for explicitly creating figuresthat include interactive tools, a toolbar, a tool-tip, andkey bindings:
pyplot.figure
- Creates a new empty
figure.Figure
or selects an existing figure pyplot.subplots
- Creates a new
figure.Figure
and fills it with a grid ofaxes.Axes
pyplot
has a notion of 'The Current Figure' which can be accessedthrough pyplot.gcf
and a notion of 'The Current Axes' accessedthrough pyplot.gca
. Almost all of the functions in pyplot
passthrough the current Figure
/ axes.Axes
(or create one) asappropriate.
Matplotlib keeps a reference to all of the open figurescreated via pyplot.figure
or pyplot.subplots
so that the figures will not be garbagecollected. Figure
s can be closed and deregistered from pyplot
individually viapyplot.close
; all open Figure
s can be closed via plt.close('all')
.
For more discussion of Matplotlib's event system and integrated event loops, please read:
New paths of cooperation for the IOF and ISF. The International School Sports Federation (ISF) and the International Orienteering Federation (IOF) signed a Memorandum of Understanding in 2016 to promote cooperation between the organisations. Learn how to turn off or uninstall OneDrive. In the Sync your OneDrive files to this PC box, check and uncheck the box at Sync all files and folders in my OneDrive. (The first check selects all the boxes, then the uncheck clears them all.). Igor Uryash, Ilya Ioff, Alexey Massarsky, Belgrade Philharmonic Orchestra. Igor Uryash, Ilya Ioff, Alexey Massarsky, Belgrade Philharmonic Orchestra. A Concert For All Seasons (CD, Album) Officina Della Musica: OdM 1017: Italy: Unknown: Sell This Version.
Discover discount designer clothing, handbags, and more at saksoff5th.com. Save up to 70% off everything with free shipping on orders of $99 or more.
IPython integration¶
We recommend using IPython for an interactive shell. In addition toall of its features (improved tab-completion, magics, multiline editing, etc),it also ensures that the GUI toolkit event loop is properly integratedwith the command line (see Command Prompt Integration).
In this example, we create and modify a figure via an IPython prompt.The figure displays in a Qt5Agg GUI window. To configure the integrationand enable interactive mode use the%matplotlib
magic:
Create a new figure window:
Add a line plot of the data to the window:
Change the color of the line from blue to orange:
If you wish to disable automatic redrawing of the plot:
If you wish to re-enable automatic redrawing of the plot:
In recent versions of Matplotlib
and IPython
, it issufficient to import matplotlib.pyplot
and call pyplot.ion
.Using the %
magic is guaranteed to work in all versions of Matplotlib and IPython.
Interactive mode¶
pyplot.ion | Turn interactive mode on. |
pyplot.ioff | Turn interactive mode off. |
pyplot.isinteractive | Return if pyplot is in 'interactive mode' or not. |
pyplot.show | Display all open figures. |
pyplot.pause | Run the GUI event loop for interval seconds. |
Interactive mode controls:
- whether created figures are automatically shown
- whether changes to artists automatically trigger re-drawing existing figures
- when
pyplot.show()
returns if given no arguments: immediately, or after all of the figures have been closed
If in interactive mode:
- newly created figures will be displayed immediately
- figures will automatically redraw when elements are changed
pyplot.show()
displays the figures and immediately returns
If not in interactive mode:
- newly created figures and changes to figures are not displayed until
pyplot.show()
is calledpyplot.pause()
is calledFigureCanvasBase.flush_events()
is called
pyplot.show()
runs the GUI event loop and does not return until all the plot windows are closed
If you are in non-interactive mode (or created figures while innon-interactive mode) you may need to explicitly call pyplot.show
to display the windows on your screen. If you only want to run theGUI event loop for a fixed amount of time, you can use pyplot.pause
.This will block the progress of your code as if you had calledtime.sleep
, ensure the current window is shown and re-drawn if needed,and run the GUI event loop for the specified period of time.
The GUI event loop being integrated with your command prompt andthe figures being in interactive mode are independent of each other.If you use pyplot.ion
but have not arranged for the event loop integration,your figures will appear but will not be interactive while the prompt is waiting for input.You will not be able to pan/zoom and the figure may not even render(the window might appear black, transparent, or as a snapshot of thedesktop under it). Conversely, if you configure the event loopintegration, displayed figures will be responsive while waiting for inputat the prompt, regardless of pyplot's 'interactive mode'.
No matter what combination of interactive mode setting and event loop integration,figures will be responsive if you use pyplot.show(block=True)
, pyplot.pause
, or runthe GUI main loop in some other way.
Warning
Using figure.Figure.show
it is possible to display a figure onthe screen without starting the event loop and without being ininteractive mode. This may work (depending on the GUI toolkit) butwill likely result in a non-responsive figure.
Default UI¶
The windows created by pyplot
have an interactive toolbar with navigationbuttons and a readout of the data values the cursor is pointing at. A number ofhelpful keybindings are registered by default.
Navigation Keyboard Shortcuts¶
The following table holds all the default keys, which can beoverwritten by use of your matplotlibrc.
Ioffer Website
Command | Default key binding and rcParam |
---|---|
Home/Reset | rcParams['keymap.home'] (default: ['h','r','home'] ) |
Back | rcParams['keymap.back'] (default: ['left','c','backspace','MouseButton.BACK'] ) |
Forward | rcParams['keymap.forward'] (default: ['right','v','MouseButton.FORWARD'] ) |
Pan/Zoom | rcParams['keymap.pan'] (default: ['p'] ) |
Zoom-to-rect | rcParams['keymap.zoom'] (default: ['o'] ) |
Save | rcParams['keymap.save'] (default: ['s','ctrl+s'] ) |
Toggle fullscreen | rcParams['keymap.fullscreen'] (default: ['f','ctrl+f'] ) |
Toggle major grids | rcParams['keymap.grid'] (default: ['g'] ) |
Toggle minor grids | rcParams['keymap.grid_minor'] (default: ['G'] ) |
Toggle x axis scale (log/linear) | rcParams['keymap.xscale'] (default: ['k','L'] ) |
Toggle y axis scale (log/linear) | rcParams['keymap.yscale'] (default: ['l'] ) |
Close Figure | rcParams['keymap.quit'] (default: ['ctrl+w','cmd+w','q'] ) |
Constrain pan/zoom to x axis | hold x when panning/zooming with mouse |
Constrain pan/zoom to y axis | hold y when panning/zooming with mouse |
Preserve aspect ratio | hold CONTROL when panning/zooming with mouse |
Other Python prompts¶
Ioffice Supersalon
Interactive mode works in the default Python prompt:
however this does not ensure that the event hook is properly installedand your figures may not be responsive. Please consult thedocumentation of your GUI toolkit for details.
Jupyter Notebooks / Lab¶
Note
To get the interactive functionality described here, you must beusing an interactive backend. The default backend in notebooks,the inline backend, is not. backend_inline
renders the figure once and inserts a static image into thenotebook when the cell is executed. Because the images are static, theycan not be panned / zoomed, take user input, or be updated from othercells.
To get interactive figures in the 'classic' notebook or Jupyter lab,use the ipympl backend(must be installed separately) which uses the ipywidget framework.If ipympl
is installed use the magic:
Ioffer Chanel Bag
to select and enable it.
Ioff White
If you only need to use the classic notebook, you can use
which uses the backend_nbagg
backend provided by Matplotlib;however, nbagg does not work in Jupyter Lab.
GUIs + Jupyter¶
You can also use one of the non-ipympl
GUI backends in a Jupyter Notebook.If you are running your Jupyter kernel locally, the GUI window will spawn onyour desktop adjacent to your web browser. If you run your notebook on a remote server,the kernel will try to open the GUI window on the remote computer. Unless you havearranged to forward the xserver back to your desktop, you will not be able tosee or interact with the window. It may also raise an exception.
PyCharm, Spyder, and VSCode¶
Ioff.de
Many IDEs have built-in integration with Matplotlib, please consult theirdocumentation for configuration details.