15

I found those two answers: Animated graphs in ipython notebook , How to grab matplotlib plot as html in ipython notebook?

But they don't address interactivity. I would like to display a plot with 2-3 curves and let the user hover those curves to receive more details or control the parameters that are used to generate those curves from a combo-box

Community
  • 1
  • 1
d1337
  • 2,543
  • 6
  • 24
  • 22

7 Answers7

9

check the following answer at iPython: Manipulate-like command.

as well as the two following directions:

  1. IPython interact/ive as motivated in IPython - The Attributes ofSoftware and How They Affect Our Work - Brian Granger near 32m:12s; and available at IPython's github
  2. Altair provides a powerful and succinct syntax, based on vega-lite; see the gallery
  3. MPLD3: Bringing Matplotlib to the Browser
eldad-a
  • 3,051
  • 3
  • 22
  • 25
  • 2
    +1 mpld3 is pretty sweet. You can just import it, and run `mpld3.enable_notebook()` below your `%pylab inline` call, and all plots become interactive. Can get a bit slow though. – naught101 Aug 25 '15 at 00:31
7

I don't believe the standard matplotlib plots are capable of the interactivity you want. Chaco can do interactive graphs, but not in an ipython notebook, AFAICT. Your best bet is probably Bokeh. It outputs to Javascript/HTML, can do interactive graphs, and has an example of using it from ipython.

AFoglia
  • 7,968
  • 3
  • 35
  • 51
  • 1
    unfortunately bokeh is going with a canvas implementation as opposed to svg, so interactivity will be severely hampered. plotly is based on d3js, allowing much richer (imo) experience – Jared Forsyth Jan 01 '14 at 13:12
7

You may want to check out Plotly. They render interactive D3 plots inside IPython Notebooks (examples here. You can export as static images as well, and zoom, hover, pan, and see text on the hover. Interactivity is one of the pitches they're emphasizing. For more, you can also use IPython widgets inside the Notebook, which gives you more control and options. For example:

enter image description here

Mateo Sanchez
  • 1,604
  • 15
  • 20
Grant
  • 83
  • 1
  • 7
  • +1 for a pointer in the right direction. If you want interactive, streaming plots embedded in an IPython notebook, (as did I) plotly is probably a better choice than bokeh (I could only get streaming scatter plots to work in bokeh, not histograms box & whisker, etc.). – nikosd Jun 19 '15 at 23:29
  • Is there a free version of Plotly? (one which does not require the user to keep their plots public, that is) – eldad-a Aug 26 '15 at 13:13
  • @eldad-a seems like you can plot privately, I plotted a few, see https://plot.ly/python/getting-started/ – eqzx Aug 27 '15 at 15:26
3

Like @AFoglia, I'm going to suggest other libraries that might be what you're looking for: Tangle, Mathematica Notebooks, IPython / Bokeh, RactiveJS, or ReactJS.

JJS
  • 59
  • 1
  • 7
2

Another solution might be the Charts library. It enables you to use the excellent Highcharts javascript library to make beautiful and interactive plots out of the box.

Some features:

  • Vector plots which you can download in .png, .jpg and .svg formats so you will never run into resolution problems.
  • Interactive charts (zoom, slide, hover over points, ...)
  • Usable in an IPython notebook
  • Explore hundreds of data structures at the same time using the asynchronous plotting capabilities.

Disclaimer: I'm the developer of the library

arnoutaertgeerts
  • 2,232
  • 5
  • 29
  • 44
1

You can run javascript straight from IPython notebooks (%%html and %%javascript), so it should be possible to run D3 code. Check this video. The exact way in which this would be implemented is not set in stone yet, as this is a feature for IPython 2.0. There are many hacks available as of now, as well as projects that try to port some characteristics of D3 to Python (such as bokeh and python-nvd3).

I have not yet tested any of these. My own bias would be to try the example below first, which is static, but uses D3 directly (so it should theoretically work for interactive plots):

dmvianna
  • 15,088
  • 18
  • 77
  • 106
1

Other answeres here seem to be outdated. IPython 2.0 has support for interactive widgets. Read the docs including some examples, but note that the nbviewer.ipython.org does not show the interactive widgets. Copy & pasting the examples to try.jupyter.org works.

lumbric
  • 7,644
  • 7
  • 42
  • 53