On Mon, Jun 30, 2008 at 5:41 AM, Stan Schymanski <[EMAIL PROTECTED]> wrote:
>
> I would like to be able to add legends to plots containing different
> lines or functions. Could anyone give an example of how to achieve
> this in SAGE?
> For example, the following plot would be nice with a legend containing
> the line colours and descriptions:
>
> sage: P1=plot(x^2,0,3)
> sage: P1=plot(x^2,0,3,rgbcolor="red")
> sage: P2=plot(x^3,0,3,rgbcolor="blue")
> sage: show(P1+P2,axes_labels=['$x$', '$y$'])
>
> I read up a bit, but wasn't able to use any of the examples given for
> Matplotlib directly in my SAGE notebook. Thanks already for your help!
>
There is unfortunately no good way to add legens to Sage plots
yet. When I desparatly need to do this, I use the text command
and explicitly put text and a line on the plot, but of course that
is not optimal.
You can use the pylab/matplotlab plotting functionality which
does allow for legends. The following illustrates using pylab,
which comes with sage, but doesn't illustrate how to make
legends (though pylab does support that).
sage: from pylab import *
sage: t = arange(0.0, 2.0, 0.01)
sage: s = sin(2*pi*t)
sage: P = plot(t, s, linewidth=1.0)
sage: xl = xlabel('time (s)')
sage: yl = ylabel('voltage (mV)')
sage: t = title('About as simple as it gets, folks')
sage: grid(True)
sage: savefig('sage.png')
I really hope somebody will add support for legends
to sage plots soon. (Emily: hint hint :-)
William
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---