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

merged 2 commits into from Apr 1, 2013


None yet
4 participants

leejjoon commented Mar 28, 2013

The problem is originally reported in the mailing list.

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


leejjoon commented Mar 28, 2013

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))
   plt.legend(handles, labels,
              bbox_to_anchor=(0., 1.02, 1., 0.102), loc=3, mode='expand',
              numpoints=1, ncol=2, borderaxespad=0.)

pelson commented Mar 28, 2013

Thanks @leejjoon this looks 👍

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

frixhax commented Mar 28, 2013

Thanks, that worked for me!


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 merged commit bf81d2b into matplotlib:v1.2.x Apr 1, 2013

1 check passed

default The Travis build passed

pelson commented Apr 2, 2013

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