-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
OrderedDict legends no longer work 2.1 #10262
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
Comments
Sorry this broke for you. Can you make a non-pandas example and I’ll try and look at what went wrong. |
oops, sorry, this is a dupe and already fixed in master, and will soon be released on 2.1.2... See #10064 |
Thanks @jklymak, it seems that my first issue is resolved by the current Curious if this is a bug or not, as the Same exact code as my first issue, but the final step of: ...
ax.legend(legend.values(), legend.keys(), loc=6, bbox_to_anchor=(1, 0.5)) Which produces the following error output: ~/Developer/.../.../.../report_functions.py in princincipal_coordinates(samples, data, features, category)
85 by_label.keys(),
86 bbox_to_anchor=(1, 1.5),
---> 87 loc=6)
88
89 text = 'Samples were rarefied to {} retaining {} of {} samples'
~/Developer/mc3/envs/.../lib/python3.5/site-packages/matplotlib/axes/_axes.py in legend(self, *args, **kwargs)
554 if len(extra_args):
555 raise TypeError('legend only accepts two non-keyword arguments')
--> 556 self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
557 self.legend_._remove_method = lambda h: setattr(self, 'legend_', None)
558 return self.legend_
~/Developer/mc3/envs/.../lib/python3.5/site-packages/matplotlib/legend.py in __init__(self, parent, handles, labels, loc, numpoints, markerscale, markerfirst, scatterpoints, scatteryoffsets, prop, fontsize, borderpad, labelspacing, handlelength, handleheight, handletextpad, borderaxespad, columnspacing, ncol, mode, fancybox, shadow, title, framealpha, edgecolor, facecolor, bbox_to_anchor, bbox_transform, frameon, handler_map)
590 del locals_view
591 # trim handles and labels if illegal label...
--> 592 for label, handle in zip(labels[:], handles[:]):
593 if (isinstance(label, six.string_types) and
594 label.startswith('_')):
TypeError: 'odict_keys' object is not subscriptable |
Looks like we need something like
|
Oh true, sorry about that, I copied from further into the real codebase, but forgot I didn't include the Here's the example sans 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)) |
Thanks @jakereps if you are able to compare my PR that'd be great, but it works w/ the test above.... |
Will do! Currently installing the PR (dropped back to |
Fixed via. #10263 |
Bug report
Legend handles and labels retrieval break as of
2.1.1
. Trying to callax.get_legend_handles_labels()
results in a comparisonValueError
being thrown.git bisect
led to 4f594f4 being the start of the issue.Code for reproduction
Actual outcome
Expected outcome
Produce a scatter plot, as expected. This worked in
2.1.0
.Matplotlib version
print(matplotlib.get_backend())
): agg on bothThe text was updated successfully, but these errors were encountered: