Stopping Legend From Overlapping the Graph

I forgot to CC the list :S

and I updated to svn trunk and it now works fine :slight_smile:

guillaume ranquet wrote:


this question raised my interest and I tried It.
unfortunately, I get errors :frowning:

when executing the demo source code linked, I get

$ python ~/
Traceback (most recent call last):
  File "/home/granquet/", line 7, in <module>
    ncol=2, mode="expand", borderaxespad=0.)
  File "/usr/lib/python2.6/site-packages/matplotlib/", line
2447, in legend
    ret = gca().legend(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/matplotlib/", line 3823,
in legend
    self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'bbox_to_anchor'

I tried with a .set_bbox_to_anchor() but I get:
AttributeError: 'Legend' object has no attribute 'set_bbox_to_anchor'

using matplotlib on linux/gentoo
am I missing something? or is my version of matplotlib not appropriate?

Jae-Joon Lee wrote:

The linked page below shows how you put the legend above the graph.

You can put it below the axes by adjusting the bbox_to_anchor parameter.
Try something like
  bbox_to_anchor=(0., -0.1, 1., -0.1), loc=1

Make sure to adjust the suplot parameter (or axes location) to make
enough room for the legend.


On Thu, Jun 25, 2009 at 9:22 PM, Chris Spencer<chrisspen@...287...> wrote:

How do you show the legend below the graph, so it doesn't overlap at
all with the graph? The docs for the legend() "loc" parameter only
seem to specify where *on* the graph you want it to show, which is
driving me nuts because even using "best", it usually hides some of my

I want to see *all* of my graph, as well as the legend. Is there any
way to do this with pylab?

Any help is appreciated.


Matplotlib-users mailing list
matplotlib-users List Signup and Options

Matplotlib-users mailing list
matplotlib-users List Signup and Options

This message contains confidential information and may contain information that is legally privileged. If you have received this message by mistake, please immediately notify us and delete the original message. Thank you.

Ce message contient des informations confidentielles. S'il vous est parvenu par erreur, merci de bien vouloir nous en aviser par retour, de n'en faire aucun usage et de n'en garder aucune copie.