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
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: martinr...@jabber.ccc.de