[IPython-dev] notebook plots via javascript

Zoltán Vörös zvoros@gmail....
Tue Jun 5 02:03:59 CDT 2012

Hi Brian,

Thanks for commenting on this issue, and also, pointing out an 
alternative approach! Here are a couple of questions.

> * I agree that interactive plotting in the notebook is really important.

We all agree on this:), but the question is still how much interactivity 
one would want. Some want to have functionality at the level of the 
Qt4/GTK backends. I think, that cannot possibly be done without 
resorting to some underlying server, but in that case, we should re-use 
Ludwig's code. Also, I can't stress enough, if we go down this path, the 
plots might be decoupled from the code that generated them. I am really 
not a great fan of any modification that cannot be back-traced, and 
modifying the plot by mouse clicks is a huge step in this direction.

Then there are those, myself included, who say that they only want to 
get more information from the plot, but they don't want to change the 
plot, except for zooming, perhaps. What could be done in pure and simple 
javascript at the moment is coordinate reporting, grid toggling, and 
cross-hairs, if there is interest in that. These I could roll out pretty 
soon. For zooming we might need a little bit of extra info from the 
middleware, as John Hunter called it, so that would require modification 
of the matplotlib code itself. The other option could be to catch the 
object returned by the backend, and insert a couple of lines in IPython 
itself. The inline backend works in a similar fashion.

One more thing that, I think, could relatively easily be implemented is 
displaying extra info as a tool-tip. An example of this is in 
http://people.iola.dk/olau/flot/examples/interacting.html .

To me, the biggest appeal of doing things at the backend's level, even 
if its capabilities are somewhat limited, is that we don't have to upset 
the code base of matplotlib.

> * I would love to see that emerge out of matplotlib, rather than YAPL
> (yet another plotting library).

Right. If we just wanted another library, then flot would probably do. 
Though, for me, one of the turn-offs is that there is no straightforward 
way of adding axis labels to a plot. I just can't imagine a plot without 
axis labels...

> Based on these observations, I am thinking of something like the following:
> * We implement a JSON backend for matplotlib.  Basically, whenever one
> of the backend methods is called, it would write to a JSON structure.
> At the end of the day, there would be a JSON structure that has the
> entire set of drawing primitives and all their details.  This part of
> the code would be fully reusable by other "frontends" and would
> provide a serialization format for matplotlib.

This seems to me as a major change in the matplotlib core itself, so we 
should call out to John Hunter, and ask his opinion...

> * We implement a JavaScript plugin/widget that works with the IPython
> Notebook that consumes that JSON and creates an interactive plot based
> on that information.  This part of the code would be specific to
> IPython.
> Does this sound reasonable?

I think this is an interesting approach, and we should mull over it. 
It's a bit of an undertaking, but it would be worthwhile.

More information about the IPython-dev mailing list