Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@leejjoon
Copy link
Contributor

The problem is originally reported in the mailing list.

http://matplotlib.1069221.n5.nabble.com/Trouble-with-legend-and-axis-scaling-tp40745.html

Basically, the legend "expand" mode fails when there is one item to show.
The PR fixes this problem.

@leejjoon
Copy link
Contributor Author

As a workaround for a current versions, one may add an invisible item. For example,

handles, labels = ax.get_legend_handles_labels()
if len(handles) == 1:
   from matplotlib.patches import Circle
   handles.append(Circle((0,0), 1, visible=False))
   labels.append("")
   plt.legend(handles, labels,
              bbox_to_anchor=(0., 1.02, 1., 0.102), loc=3, mode='expand',
              numpoints=1, ncol=2, borderaxespad=0.)

@pelson
Copy link
Member

pelson commented Mar 28, 2013

Thanks @leejjoon this looks 👍

Is it easy to add/update a test for this?

@frixhax
Copy link

frixhax commented Mar 28, 2013

Thanks, that worked for me!

@pelson
Copy link
Member

pelson commented Mar 30, 2013

Is it easy to add/update a test for this?

Bump. I'm happy to merge this, but it'd be even better if we had a test to ensure we don't digress in the future.

Thanks @leejjoon

dmcdougall added a commit that referenced this pull request Apr 1, 2013
fix legend w/ 'expand' mode which fails for a single item.
@dmcdougall dmcdougall merged commit bf81d2b into matplotlib:v1.2.x Apr 1, 2013
@pelson
Copy link
Member

pelson commented Apr 2, 2013

Thanks @leejjoon & @dmcdougall!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.