2009/4/16 Ondrej Certik <ond...@certik.cz>:
>
> Hi,
>
> the notebook (sagelite) can work with Graphics primitives in Sage,
> that's very nice.
>
> I would like to make sympy (and other packages) to be able to easily
> work with the plotting. One way to do plotting is to use matplotlib
> (or anything else) and drop a .png file, the notebook will show it.
>
> But I think a better way is to just return a Graphics object, as described at:
>
> http://sagemath.org/doc/reference/sage/plot/plot.html
>
> since the notebook can plot that one too.

The notebook plots graphics objects by just making the show command
(on a graphics object) output a png.   There is nothing at all special
about how the notebook plots Graphics 2d objects -- anything that
outputs a png gets "plotted" and that is it.  It's an incredibly
simple "protocol", but means that you just immediately use it in your
code.

>  That would work for 2D
> plots. For 3D plots, Sage seems to be using a little bit different
> architecture:
>
> sage: G = plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2))
> sage: type(G)
> <type 'sage.plot.plot3d.parametric_surface.ParametricSurface'>
>
> as described at:
>
> http://sagemath.org/doc/reference/plot3d.html

For 3d plots it's really very similar, but of course they aren't
always png's.  Calling show with viewer="tachyon" just renders a png,
and we're in the above case.  Calling show with no options (no
viewer="tachyon") uses jmol, which means that a certain file type is
output.  The notebook then notices that file was created and embeds a
java jmol applet configured using that file.

Anyway, I'm just hopefully clarifying how things work now.  I'm not
actually answering your questions below though.

>
>
> What is the best way to get other packages using it too? So that they
> play nicely with the notebook and also with Sage, if the user install
> them in Sage, but also outside Sage, if the user wants to use just the
> package + notebook, or even a command line, in which case it should
> popup a matplotlib window (and mayavi window in 3D for me).
>
> I think the way to do it would be that the library (be it sympy or
> anything else) would have some plot command/method, that returns an
> instance,
>
> G = plot(something)
>
> that has some common API, e.g. a
>
> G._plot_()
>
> method and the Sage notebook would check if the returned object has
> such a method and if so, just call it to produce a plot, it could
> accept a parameter, like
>
> G._plot_(method="notebook")
>
> that would produce a .png image, or
>
> G._plot_(method="commandline")
>
> that would popup a matplotlib/mayavi/whatever window. It seems to me
> that in Sage, the G._plot_ method is actually called G.show() and
> G.save() ?
>
>
> As to handling different axes/zoom in/out, in Sage, the G object has
> methods like .xmax() and it seems to work nice.
> But that is a business of the G object, as far as Sage is concerned,
> as long as the object has _plot_ method (or "show", whatever the name
> is), it just calls it?
>
> So we just need to support this API and that's it. Is show() and
> save() the only two methods we need to implement? Or is there anything
> else?
>
> Ondrej
>
> >
>



-- 
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to