ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 26 Oct 2011 15:44:51 +0200a functional java applet for 2d plotshttps://ask.sagemath.org/question/8387/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](http://academic.sun.ac.za/mathed/java/Index.htm) is the example, maybe, even not the best one.
Mon, 17 Oct 2011 10:35:53 +0200https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/Answer by Jason Grout for <p>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:</p>
<pre><code>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)
</code></pre>
<p>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. <a href="http://academic.sun.ac.za/mathed/java/Index.htm">Here</a> is the example, maybe, even not the best one.</p>
https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?answer=12777#post-id-12777There 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/Mon, 17 Oct 2011 16:44:09 +0200https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?answer=12777#post-id-12777Answer by kcrisman for <p>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:</p>
<pre><code>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)
</code></pre>
<p>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. <a href="http://academic.sun.ac.za/mathed/java/Index.htm">Here</a> is the example, maybe, even not the best one.</p>
https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?answer=12775#post-id-12775There has been discussion of using [flot](http://code.google.com/p/flot/), and [this Trac ticket](http://trac.sagemath.org/sage_trac/ticket/11489) 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](http://trac.sagemath.org/sage_trac/ticket/5448).
There is a whole [thread on sage-devel](http://groups.google.com/group/sage-devel/browse_thread/thread/91c424ccb670ed4b?pli=1) from 2009 about flot etc. as well, and then [this follow-up thread](http://groups.google.com/group/sage-devel/browse_thread/thread/221ebcb20940d8dc/f20b7ce07df12c81).
See also [this worksheet](http://www.sagenb.org/home/pub/285/) on 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.Mon, 17 Oct 2011 14:36:12 +0200https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?answer=12775#post-id-12775Comment by Jason Grout for <p>There has been discussion of using <a href="http://code.google.com/p/flot/">flot</a>, and <a href="http://trac.sagemath.org/sage_trac/ticket/11489">this Trac ticket</a> has some nice examples of using Geogebra inside Sage. </p>
<p>But this isn't really a full answer!</p>
<p>+++ </p>
<p>Edit: after the comment, I added these comments. Maybe adding flot really <em>is</em> easy?</p>
<p>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 <a href="http://trac.sagemath.org/sage_trac/ticket/5448">Trac ticket 5448</a>.</p>
<p>There is a whole <a href="http://groups.google.com/group/sage-devel/browse_thread/thread/91c424ccb670ed4b?pli=1">thread on sage-devel</a> from 2009 about flot etc. as well, and then <a href="http://groups.google.com/group/sage-devel/browse_thread/thread/221ebcb20940d8dc/f20b7ce07df12c81">this follow-up thread</a>.</p>
<p>See also <a href="http://www.sagenb.org/home/pub/285/">this worksheet</a>on <a href="http://sagenb.org">sagenb.org</a>, 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.</p>
https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?comment=21064#post-id-21064I 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.Sat, 22 Oct 2011 04:10:08 +0200https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?comment=21064#post-id-21064Comment by ADuC812 for <p>There has been discussion of using <a href="http://code.google.com/p/flot/">flot</a>, and <a href="http://trac.sagemath.org/sage_trac/ticket/11489">this Trac ticket</a> has some nice examples of using Geogebra inside Sage. </p>
<p>But this isn't really a full answer!</p>
<p>+++ </p>
<p>Edit: after the comment, I added these comments. Maybe adding flot really <em>is</em> easy?</p>
<p>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 <a href="http://trac.sagemath.org/sage_trac/ticket/5448">Trac ticket 5448</a>.</p>
<p>There is a whole <a href="http://groups.google.com/group/sage-devel/browse_thread/thread/91c424ccb670ed4b?pli=1">thread on sage-devel</a> from 2009 about flot etc. as well, and then <a href="http://groups.google.com/group/sage-devel/browse_thread/thread/221ebcb20940d8dc/f20b7ce07df12c81">this follow-up thread</a>.</p>
<p>See also <a href="http://www.sagenb.org/home/pub/285/">this worksheet</a>on <a href="http://sagenb.org">sagenb.org</a>, 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.</p>
https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?comment=21081#post-id-21081Thanks 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?Thu, 20 Oct 2011 02:00:35 +0200https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?comment=21081#post-id-21081Comment by ADuC812 for <p>There has been discussion of using <a href="http://code.google.com/p/flot/">flot</a>, and <a href="http://trac.sagemath.org/sage_trac/ticket/11489">this Trac ticket</a> has some nice examples of using Geogebra inside Sage. </p>
<p>But this isn't really a full answer!</p>
<p>+++ </p>
<p>Edit: after the comment, I added these comments. Maybe adding flot really <em>is</em> easy?</p>
<p>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 <a href="http://trac.sagemath.org/sage_trac/ticket/5448">Trac ticket 5448</a>.</p>
<p>There is a whole <a href="http://groups.google.com/group/sage-devel/browse_thread/thread/91c424ccb670ed4b?pli=1">thread on sage-devel</a> from 2009 about flot etc. as well, and then <a href="http://groups.google.com/group/sage-devel/browse_thread/thread/221ebcb20940d8dc/f20b7ce07df12c81">this follow-up thread</a>.</p>
<p>See also <a href="http://www.sagenb.org/home/pub/285/">this worksheet</a>on <a href="http://sagenb.org">sagenb.org</a>, 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.</p>
https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?comment=21028#post-id-21028I had a look on mplh5canvas, which is already an embeddable into html interactive backend for matplotlib. It could do well instead of flot, however, the way it works seem to be quite strange: it creates a webserver, where an interactive plot is shown. This hangs on the python process until server shutdown. Do not think this is handy for sage. On the contrary, flot backend for matplotlib should act as a separate standalone webpage, as all the interactivity will work through javascript. I think we will try writing a matplotlib backend for flot in the near future. Any help is welcome but beforehand we will investigate how to start.Wed, 26 Oct 2011 15:44:51 +0200https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?comment=21028#post-id-21028Comment by kcrisman for <p>There has been discussion of using <a href="http://code.google.com/p/flot/">flot</a>, and <a href="http://trac.sagemath.org/sage_trac/ticket/11489">this Trac ticket</a> has some nice examples of using Geogebra inside Sage. </p>
<p>But this isn't really a full answer!</p>
<p>+++ </p>
<p>Edit: after the comment, I added these comments. Maybe adding flot really <em>is</em> easy?</p>
<p>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 <a href="http://trac.sagemath.org/sage_trac/ticket/5448">Trac ticket 5448</a>.</p>
<p>There is a whole <a href="http://groups.google.com/group/sage-devel/browse_thread/thread/91c424ccb670ed4b?pli=1">thread on sage-devel</a> from 2009 about flot etc. as well, and then <a href="http://groups.google.com/group/sage-devel/browse_thread/thread/221ebcb20940d8dc/f20b7ce07df12c81">this follow-up thread</a>.</p>
<p>See also <a href="http://www.sagenb.org/home/pub/285/">this worksheet</a>on <a href="http://sagenb.org">sagenb.org</a>, 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.</p>
https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?comment=21070#post-id-21070The link just changed, since the sagenb structure changed. I've added this to my answer.Fri, 21 Oct 2011 14:21:35 +0200https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?comment=21070#post-id-21070Comment by process91 for <p>There has been discussion of using <a href="http://code.google.com/p/flot/">flot</a>, and <a href="http://trac.sagemath.org/sage_trac/ticket/11489">this Trac ticket</a> has some nice examples of using Geogebra inside Sage. </p>
<p>But this isn't really a full answer!</p>
<p>+++ </p>
<p>Edit: after the comment, I added these comments. Maybe adding flot really <em>is</em> easy?</p>
<p>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 <a href="http://trac.sagemath.org/sage_trac/ticket/5448">Trac ticket 5448</a>.</p>
<p>There is a whole <a href="http://groups.google.com/group/sage-devel/browse_thread/thread/91c424ccb670ed4b?pli=1">thread on sage-devel</a> from 2009 about flot etc. as well, and then <a href="http://groups.google.com/group/sage-devel/browse_thread/thread/221ebcb20940d8dc/f20b7ce07df12c81">this follow-up thread</a>.</p>
<p>See also <a href="http://www.sagenb.org/home/pub/285/">this worksheet</a>on <a href="http://sagenb.org">sagenb.org</a>, 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.</p>
https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?comment=21037#post-id-21037@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.Tue, 25 Oct 2011 11:03:43 +0200https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?comment=21037#post-id-21037Comment by ADuC812 for <p>There has been discussion of using <a href="http://code.google.com/p/flot/">flot</a>, and <a href="http://trac.sagemath.org/sage_trac/ticket/11489">this Trac ticket</a> has some nice examples of using Geogebra inside Sage. </p>
<p>But this isn't really a full answer!</p>
<p>+++ </p>
<p>Edit: after the comment, I added these comments. Maybe adding flot really <em>is</em> easy?</p>
<p>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 <a href="http://trac.sagemath.org/sage_trac/ticket/5448">Trac ticket 5448</a>.</p>
<p>There is a whole <a href="http://groups.google.com/group/sage-devel/browse_thread/thread/91c424ccb670ed4b?pli=1">thread on sage-devel</a> from 2009 about flot etc. as well, and then <a href="http://groups.google.com/group/sage-devel/browse_thread/thread/221ebcb20940d8dc/f20b7ce07df12c81">this follow-up thread</a>.</p>
<p>See also <a href="http://www.sagenb.org/home/pub/285/">this worksheet</a>on <a href="http://sagenb.org">sagenb.org</a>, 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.</p>
https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?comment=21074#post-id-21074After 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/dataFri, 21 Oct 2011 02:36:25 +0200https://ask.sagemath.org/question/8387/a-functional-java-applet-for-2d-plots/?comment=21074#post-id-21074