Ask Your Question

a functional java applet for 2d plots

asked 2011-10-17 10:35:53 +0100

ADuC812 gravatar image

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))
def _(b = slider(-1, 1, 0.01, default=0.5, label='cursor')):
   p2=line(((b,-1),(b,1)), color='green')

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 flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2011-10-17 14:36:12 +0100

kcrisman gravatar image

updated 2011-10-21 14:24:41 +0100

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, 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.

edit flag offensive delete link 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?

ADuC812 gravatar imageADuC812 ( 2011-10-20 02:00:35 +0100 )edit

After studying the links you posted I really am in doubt: there was a working example ( - 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

ADuC812 gravatar imageADuC812 ( 2011-10-21 02:36:25 +0100 )edit

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

kcrisman gravatar imagekcrisman ( 2011-10-21 14:21:35 +0100 )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.

Jason Grout gravatar imageJason Grout ( 2011-10-22 04:10:08 +0100 )edit

@Jason Grout I would love to see flot working (or is mathplotlib the preffered solution? (it doesn't seem to be interactive yet)[]). 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.

process91 gravatar imageprocess91 ( 2011-10-25 11:03:43 +0100 )edit

answered 2011-10-17 16:44:09 +0100

Jason Grout gravatar image

There is not an easy way already written, that I know of. I did use jsxgraph in a worksheet here:

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2011-10-17 10:35:53 +0100

Seen: 749 times

Last updated: Oct 21 '11