d1337
d1337

Reputation: 2753

Is there a way to create interactive plots (a la D3) in IPython notebooks?

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

Upvotes: 15

Views: 7252

Answers (7)

eldad-a
eldad-a

Reputation: 3191

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

Upvotes: 9

Grant
Grant

Reputation: 83

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

Upvotes: 7

lumbric
lumbric

Reputation: 9063

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.

Upvotes: 1

arnoutaertgeerts
arnoutaertgeerts

Reputation: 2322

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

Upvotes: 2

dmvianna
dmvianna

Reputation: 15718

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):

Upvotes: 1

JJS
JJS

Reputation: 79

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.

Upvotes: 3

AFoglia
AFoglia

Reputation: 8128

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.

Upvotes: 7

Related Questions