# a functional java applet for 2d plots

3d plotting with jmol is great idea. However, all what I find for 2d plotting generates a picture only. I'd like to have an applet for that which supports cursors, zooming, maybe hiding certain plotted lines and other interactive control elements. Of course, this can be somehow done with @interact, but the applet would work much faster than the link browser-worksheet-sage. At least, an attempt to introduce cursor did not seem to have a handy result:

p1=plot (sin(x))
@interact
def _(b = slider(-1, 1, 0.01, default=0.5, label='cursor')):
p2=line(((b,-1),(b,1)), color='green')
show(p1+p2,xmin=-1,xmax=1,ymax=1,ymin=-1)


Does anybody know if there is an easy way to do this, or if there is not, where one may start integrating such an applet into sage? There are a number of open-source graphing applets. Here is the example, maybe, even not the best one.

edit retag close merge delete

Sort by » oldest newest most voted

There has been discussion of using flot, and this Trac ticket has some nice examples of using Geogebra inside Sage.

But this isn't really a full answer!

+++

Edit: after the comment, I added these comments. Maybe adding flot really is easy?

Jason seems to have thought at one point that using flot would be easy - see "After this change, it will be trivial to add a viewer='flot' option to Graphics." at Trac ticket 5448.

There is a whole thread on sage-devel from 2009 about flot etc. as well, and then this follow-up thread.

See also this worksheeton sagenb.org, called FLOTEXAMPLE. It looks to be a decent mockup, though there is a syntax warning, and in my browser clicking on "Win.html" doesn't bring up the full flot capability.

more

Thanks for the answer. flot or jsxgraph from post below will certainly do the trick. It should not be too hard to implement something like MyOwnClass.flot() which will plot data from MyOwnClass using flot. However, it would be nice to integrate into sage function like flot(sage.plot.plot.Graphics) which will produce a flot graph as close as possible to a matplotlib analog. Studying source, I found that all actual plotting is embedded into _render_on_subplot() functions of primitives. I'd possibly have to modify or write an alternatives to all these to support either flot or matplotlib? Or what would be 'a sage way' of such an integration?

( 2011-10-19 19:00:35 -0600 )edit

After studying the links you posted I really am in doubt: there was a working example (http://www.sagenb.org/pub/285/ - is not available now), so many people appreciated it - and after all no attempt of real integration was made. I have a new question now: where to put flot library into sage folder to make it available for loading from the worksheet. There were some clues for that in the discussions, but the info seem to be really outdated. UPD: found it myself: sage/devel/sagenb-main/sagenb/data

( 2011-10-20 19:36:25 -0600 )edit

The link just changed, since the sagenb structure changed. I've added this to my answer.

( 2011-10-21 07:21:35 -0600 )edit

I think if you wanted to pursue this, the most fruitful avenue might be to write a matplotlib backend. That should be fairly straightfoward (you just need to implement some primitives like drawing a line, etc). Once it is done, we and lots of other people will automatically have access to it.

( 2011-10-21 21:10:08 -0600 )edit

@Jason Grout I would love to see flot working (or is mathplotlib the preffered solution? (it doesn't seem to be interactive yet)[http://code.google.com/p/mplh5canvas/]). What steps can I take to help with this? I know more web design than Python, but I'm familiar with enough python to work my way through Django setups and use Sage.

( 2011-10-25 04:03:43 -0600 )edit

There is not an easy way already written, that I know of. I did use jsxgraph in a worksheet here: http://sage.cs.drake.edu/home/pub/81/

more