Skip to content

FIX: (re-allow) legend OrderedDict handles and labels... #10263

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

Merged
merged 2 commits into from
Jan 17, 2018

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Jan 16, 2018

PR Summary

As reported in #10262, OrderedDict input no longer works in 2.1.1. i.e.

import collections
import matplotlib.pyplot as plt
import numpy as np

X = np.random.randn(10)
Y = np.random.randn(10)
labels = ['a'] * 5 + ['b'] * 5
colors = ['r'] * 5 + ['g'] * 5

fig, ax = plt.subplots()
for x, y, label, color in zip(X, Y, labels, colors):
    ax.scatter(x, y, label=label, c=color)

handles, labels = ax.get_legend_handles_labels()
legend = collections.OrderedDict(zip(labels, handles))
ax.legend(legend.values(), legend.keys(), loc=6, bbox_to_anchor=(1, .5))

This PR fixes that (thanks @anntzer) and adds a small test...

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant

@jklymak jklymak added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Jan 16, 2018
@jklymak jklymak added this to the v2.1.2 milestone Jan 16, 2018
else:
_lab.append(label)
_hand.append(handle)
label, handle = _lab, _hand
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plural!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh duh!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That certainly fixed it alright ;-)

@jklymak jklymak force-pushed the fix-legend-ordereddict branch from 9cc2506 to 3d65ca1 Compare January 16, 2018 23:51
@anntzer anntzer dismissed their stale review January 17, 2018 01:31

untypoed

@tacaswell tacaswell merged commit 4f9458d into matplotlib:master Jan 17, 2018
@lumberbot-app
Copy link

lumberbot-app bot commented Jan 17, 2018

There seem to be a conflict, please backport manually

@jklymak jklymak deleted the fix-legend-ordereddict branch January 17, 2018 19:16
tacaswell added a commit that referenced this pull request Jan 18, 2018
FIX: (re-allow) legend OrderedDict handles and labels...
Conflicts:
	lib/matplotlib/legend.py
          - conflicts on patch, kept backported version
@tacaswell
Copy link
Member

backported to v2.1.x as c125ab4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants