Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix legend w/ 'expand' mode which fails for a single item. #1864

Merged
merged 2 commits into from Apr 1, 2013

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.

None yet

4 participants