Problem assigning labels in legends

Hi

In one part of my script I plot some lines
and assign labels to the lines.

Later in the script I create a figure legend.

How do I get the labels, that I assigned at plot-time, to
be used in the legend? Currently I am manually
specifying the legend labels.

# Plot some lines ... set values for the labels
ax.plot(r.date, r.FSA, label='FSA-Load-Pct')
ax.plot(r.date, r.FSB, label='FSB-Load-Pct')
ax.plot(r.date, r.Heap, label='Heap-Use-Pct')
.
.
.
.
.
# now setup the legend for the figure
# It would be nice to be able to use the labels already assigned
# to the lines .. rather than having to manually respecify the labels for
# the legend

mylines=ax.get_lines()
# mylables=ax.get_line_labels() I WISH THIS WAS POSSIBLE !!

# this is one line may wrap in the email message
figlegend = fig0.legend(mylines, ('FSA-Load-Pct','FSB-Load-Pct','Heap-Use-Pct'), loc=(0.5,0.01), prop=matplotlib.font_manager.FontProperties(size='smaller'))

Thanks
Andy

Is there any specific reason that you have to use figlegend, instead
of "legend"?
I'm asking this because the "legend" command automatically collect all
the relevant information for you, i.e., you can just do

legend()

Of course the legend is displayed inside the axes unlike the figlegend.

If you're running the svn version of the mpl, you may place the (axes)
legend at the figure corner by doing

l = legend()
l.set_bbox_to_anchor([0, 0, 1, 1], transform=gcf().transFigure)

Anyhow,

# mylables=ax.get_line_labels() I WISH THIS WAS POSSIBLE !!

You can simply do

mylables= [l.get_label() for l in mylines]

Regards,

-JJ

ยทยทยท

On Thu, Apr 30, 2009 at 12:09 PM, Andrew Romero <romeroajr@...9...> wrote:

Hi

In one part of my script I plot some lines
and assign labels to the lines.

Later in the script I create a figure legend.

How do I get the labels, that I assigned at plot-time, to
be used in the legend? Currently I am manually
specifying the legend labels.

# Plot some lines ... set values for the labels
ax.plot(r.date, r.FSA, label='FSA-Load-Pct')
ax.plot(r.date, r.FSB, label='FSB-Load-Pct')
ax.plot(r.date, r.Heap, label='Heap-Use-Pct')
.
.
.
.
.
# now setup the legend for the figure
# It would be nice to be able to use the labels already assigned
# to the lines .. rather than having to manually respecify the labels for
# the legend

mylines=ax.get_lines()
# mylables=ax.get_line_labels() I WISH THIS WAS POSSIBLE !!

# this is one line may wrap in the email message
figlegend = fig0.legend(mylines, ('FSA-Load-Pct','FSB-Load-Pct','Heap-Use-Pct'), loc=(0.5,0.01), prop=matplotlib.font_manager.FontProperties(size='smaller'))

Thanks
Andy

------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options