Thanks a lot, that's great! I don't understand how to change the
legend descriptioins "Foo" and "Bar" in the first example, but the
second one is pretty straightforward. I look forward to an
implemenation in SAGE plot.

Regards,
Stan

On Jun 30, 4:13 pm, Martin Albrecht <[EMAIL PROTECTED]>
wrote:
> On Monday 30 June 2008, William Stein wrote:
>
>
>
> > 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).
>
> This one does:
>
> # data
> x = srange(10)
> d1 = [e^1.8 for e in x]
> d2 = [e^1.7 + 1.2 for e in x]
>
> import pylab
> pylab.clf() # clear the figure first
> pylab.figure(1)
> # plot some data and add a legend
> pylab.plot(x,d1, label="Foo")
> pylab.plot(x,d2,label="Bar")
> pylab.legend() # print the legend
> pylab.title("$n^X$ FooBar")
> pylab.ylabel("fubar") # label the axes
> pylab.xlabel("0-9")
> pylab.savefig('foo.png',dpi=72) # fire!
>
> --
> name: Martin Albrecht
> _pgp:http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99
> _www:http://www.informatik.uni-bremen.de/~malb
> _jab: [EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to