I am using IPython with --pylab=inline and would sometimes like to quickly switch to the interactive, zoomable Matplotlib GUI for viewing plots (the one that pops up when you plot something in a terminal Python console). How could I do that? Preferably without leaving or restarting my notebook.
The problem with inline plots in IPy notebook is that they are of a limited resolution and I can't zoom into them to see some smaller parts. With the Maptlotlib GUI that starts from a terminal I can select a rectangle of the graph that I want to zoom into and the axes adjust accordingly. I tried experimenting with
from matplotlib import interactive
interactive(True)
and
interactive(False)
but that didn't do anything. I couldn't find any hint online either.
If all you want to do is to switch from inline plots to interactive and back (so that you can pan/zoom), it is better to use %matplotlib magic.
and back to html
%pylab magic imports a bunch of other things and may even result in a conflict. It does "from pylab import *".
You also can use new notebook backend (added in matplotlib 1.4):
If you want to have more interactivity in your charts, you can look at mpld3 and bokeh. mpld3 is great, if you don't have ton's of data points (e.g. <5k+) and you want to use normal matplotlib syntax, but more interactivity, compared to %matplotlib notebook . Bokeh can handle lots of data, but you need to learn it's syntax as it is a separate library.
Also you can check out pivottablejs (pip install pivottablejs)
However cool interactive data exploration is, it can totally mess with reproducibility. It has happened to me, so I try to use it only at the very early stage and switch to pure inline matplotlib/seaborn, once I got the feel for the data.
I'm using ipython in "jupyter QTConsole" from Anaconda at www.continuum.io/downloads on 5/28/20117.
Here's an example to flip back and forth between a separate window and an inline plot mode using ipython magic.
Starting with matplotlib 1.4.0 there is now an an interactive backend for use in the notebook
There are a few version of IPython which do not have that alias registered, the fall back is:
If that does not work update you IPython.
To play with this, goto tmpnb.org
and paste
into a code cell (or just modify the existing python demo notebook)
According to the documentation, you should be able to switch back and forth like this:
and that will pop up a regular plot window (a restart on the notebook may be necessary).
I hope this helps.
A better solution for your problem might be the Charts library. It enables you to use the excellent Highcharts javascript library to make beautiful and interactive plots. Highcharts uses the HTML
svg
tag so all your charts are actually vector images.Some features:
Disclaimer: I'm the developer of the library
Restart kernel and clear output (if not starting with new notebook), then run
For more info go to Plotting with matplotlib