Legend outside plot

Hi, I'm trying to get matplotlib to give me a plot where the legend is outside the axes.

  I saw several posts about this in the mailing list archives, but none of them really seem to provide workable solutions. Using Figure.legend() doesn't really put the legend outside the figure, because it doesn't resize the axes, so the legend just overlaps the figure.

  In the spirit of open source, I thought I'd try to do it myself. But I can't even figure out how the various matplotlib objects are being positioned in the window. Like, I can get some info about the axes with axes.get_position(), and I can get some info about the legend with legend.get_window_extent().get_bounds(), but the former is just proportional size information relative to the figure as a whole, and the second is in some coordinates I don't know how to interpret. How can I get information about the bounding boxes of the actual plot (i.e., the axes and plot area including ticks and labels) and the legend, in compatible numbers that will allow me to determine whether they overlap?

  Or, alternatively, is there some easier way to get legends to NEVER overlap lines? I'm rather surprised that there seems to be no way to guarantee this, since it seems like an obvious thing to want, and also since there seem to be a bunch of requests for it on the mailing list.

  Thanks for the help.

···

--
--Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail."
  --author unknown

  Hi, I'm trying to get matplotlib to give me a plot where the legend is
outside the axes.

  I saw several posts about this in the mailing list archives, but none of
them really seem to provide workable solutions.

Try passing the loc kwarg to legend(). Like legend([...], loc=(1.01, 0.25))

        Or, alternatively, is there some easier way to get legends to NEVER
overlap lines?

try legend([...], loc='best')

Darren

···

On Wednesday 16 August 2006 02:26, Brendan Barnwell wrote:

[I accidentally sent this message privately to the sender before. . . why doesn't this list set the Reply-To header to the list?]

Darren Dale wrote:

  Hi, I'm trying to get matplotlib to give me a plot where the legend is
outside the axes.

  I saw several posts about this in the mailing list archives, but none of
them really seem to provide workable solutions.

Try passing the loc kwarg to legend(). Like legend([...], loc=(1.01, 0.25))

  Thanks, that works after a fashion. Again, though, I can't figure out a
programmatic way to decide what values to use there. I would like to be able to
calculate the size of the window, calculate the size of the legend, and then set
the size of the axes so that everything fits nicely.

  Why is it that the sizes and positions for axes and legends are specified in
totally different units (proportional vs. pixel)? Is there a way to say "I want
the axes to take up 80% of the window and the legend to take up the remaining
20%"? Is there a way to change the format of the legend, so that it is, for
example, in two columns instead of one? Or to get the legend text to word wrap
within a fixed-width box instead of just causing the legend box to grow without
bound? What I'm trying to do is figure out how to programmatically arrange the
various elements in the plot window so that they look nice.

  I guess the simplest question I can ask is: how can I getthe width of the legend and the width of the axes in comparable units? If I could at least get that, I could manually calculate how big the axes should be.

        Or, alternatively, is there some easier way to get legends to NEVER
overlap lines?

try legend([...], loc='best')

  That doesn't work, because 'best' apparently isn't implemented for figure
legends, and if I use an axes legend then it sometimes overlaps the lines.

-- --Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown

···

On Wednesday 16 August 2006 02:26, Brendan Barnwell wrote:

I don't think mailing lists should change the reply-to:

http://www.unicom.com/pw/reply-to-harmful.html

Cheers
Stéfan

···

On Thu, Aug 17, 2006 at 09:48:58PM -0700, Brendan Barnwell wrote:

[I accidentally sent this message privately to the sender before. . . why
doesn't this list set the Reply-To header to the list?]

Stefan van der Walt wrote:

···

On Thu, Aug 17, 2006 at 09:48:58PM -0700, Brendan Barnwell wrote:

[I accidentally sent this message privately to the sender before. . . why doesn't this list set the Reply-To header to the list?]

I don't think mailing lists should change the reply-to:

Telepathy - Powering Successful Brands

  As per the instructions on that page, I am sending this reply by using my client's "reply to all" feature. If you receive two copies of this email (one from me and one from the list) then I suspect you will understand the disadvantage of this mechanism.

--
--Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail."
  --author unknown

Stefan van der Walt wrote:

I don't think mailing lists should change the reply-to:

Telepathy - Powering Successful Brands

The principles in that article are sound, but the conclusions simply don't match my experience. I'm on a half a dozen or so lists. Some re-set the reply-to header, and some don't. I am very familiar with "reply" vs. "reply all" -- I use them selectively every day, for all my email.

I very frequently do NOT do what I intended with this list and others that don't set the reply-to header. I NEVER make a mistake or have a hard time with the lists that do. That's just me, but I'll address a couple points in that article:

"""
It Adds Nothing: "...another that replies to the author plus all of the list recipients..."
"""

Here's what the author is missing: "Reply All" replies to all, not just the group. That means I have just sent a message to the list and to the original author -- that author gets two copies of my message, which is only a minor annoyance. However, when someone responds to my response, now two people are on the "all" list. Then another response, and pretty soon I'm getting 5 copies of the same message -- now it's gone beyond just annoying. Add cross-posing, and it really gets ugly.

NOTE: With this particular note, reply-all only replied to the list -- what's different about how you send your mail?

"""
Principle of Least Surprise
"""

When I get a message from a list, I think of it being from the list, not from any particular author, so I am surprised when my reply goes only to that author. I have been bit by this many, many times.

"""
Principle of Least Damage

Consider the damage when things go awry. If you do not munge the Reply-To header and a list subscriber accidentally sends a response via private email instead of to the list, he or she has to follow up with a message that says, "Ooops! I meant to send that to the list. Could you please forward a copy for me." That's a hassle, and it happens from time to time.
"""

It happens a LOT, and it's not always obvious. The purpose of lists is to foster group communication and public archiving -- it should be optimized for that, not for private communication.

"""
What happens, however, when a person mistakenly broadcasts a private message to the entire list? I
"""
I very, very, rarely send truly private responses to list messages. It's not rare for me to send messages that are of little interest to the list, and I do send those privately, but there is no harm done if these get broadcast unintentionally.

"""
Guess what feature more and more people are asking for? A third reply command -- one that ignores any existing Reply-To header!
"""

Actually, what I would want, for lists that don't munge the reply-to, is a third option: one that sends the message only to the list, and not to "all" -- I think that's the same thing, actually, reply to only the sender, not the reply-to.

"""
One day I accidentally sent a private, personal reply out over one of my own damn lists.
"""

I don't know how many times I've seen "reply-all" accidentally used for a message that should have been just "reply". People do this at work every day, and while most of them are harmless annoyances, occasionally someone does send a truly personal message out that way -- oops! My personal solution is to get in the habit of using only "reply". That way I have to think about it when I want to send something out to everyone, not when I don't want to. If I was using "reply-all" with my list traffic, I'd be getting into a bad habit.

This all comes down to the key paradox of usability -- "intuitive" means that something works like one expects -- but different people expect different things, I clearly expect different things than the author of that article. However, here's my attempt to use logical reasoning:

Munging the reply-to header on a list makes it easier for what most people need to do most of the time: reply to the list, and only the list.

The ONLY significant consequence to munging the header is that someone MIGHT be more likely to accidentally sent out a truly personal note to the list. However, I argue that:

1) anyone should be very, very careful every time they send a truly personal email anyway -- email is a pretty risky medium for such messages.

2) Getting in the habit of hitting reply-all will make it just as likely to make the mistake of sending a personal note to the list, and more likely that you'll make that mistake with other, non-list email.

Wow, that turned out to be a long way to say:

+1 on re-setting the reply-to headers.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

I too would like a simple “Reply” to go to the list. I had to use Gmail’s “Reply to all” feature to put this on the list.