Repository navigation
Closed
Labels
Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Milestone
Description
Bug report
figure.legend no longer accepts "handles" and and "labels" as keywords
Code for reproduction
# Paste your code here
#
#
fig.legend(
handles = patches,
labels = labels,
...)
**Actual outcome**
<!--The output produced by the above code, which may be a screenshot, console output, etc.-->If applicable, paste the console output here
~/Python/lib/python3.6/site-packages/matplotlib/figure.py in legend(self, *args, **kwargs)
1523 '(artist handles, figure labels, legend location)')
1524
-> 1525 l = Legend(self, handles, labels, **kwargs)
1526 self.legends.append(l)
1527 l._remove_method = lambda h: self.legends.remove(h)
TypeError: init() got multiple values for argument 'handles'
**Expected outcome**
<!--A description of the expected outcome from the code snippet-->
<!--If this used to work in an earlier version of Matplotlib, please note the version it used to work on-->
**Matplotlib version**
<!--Please specify your platform and versions of the relevant libraries you are using:-->
* Operating system: Fedora 26
* Matplotlib version: 2.1
* Matplotlib backend (`print(matplotlib.get_backend())`): TkAgg
* Python version: 3.6.3
* Jupyter version (if applicable):
* Other libraries:
<!--Please tell us how you installed matplotlib and python e.g., from source, pip, conda-->
<!--If you installed from conda, please specify which channel you used if not the default-->
**Fix**
if handles and labels are provided as kwargs, use these and pop from kwargs.
Reacted by Joel Nothman
Metadata
Metadata
Assignees
Labels
Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Activity
2sn commentedon Oct 8, 2017
There is many more issues. mpl 2.1.0 is not a production version.
tacaswell commentedon Oct 8, 2017
Can you please provide a runnable example?
jklymak commentedon Oct 8, 2017
Doesn't make a legend and returns:
This is using master.
jklymak commentedon Oct 8, 2017
@dstansby It looks like you maybe made this change? Are we dropping support for
handlesandlabelskeywords?@2sn : positional arguments work, and indeed the documented version of
figure.legenddon't make mention of supportinghandles=:dstansby commentedon Oct 8, 2017
Do you have a PR/commit reference for where I made the change? Can't remember anything like this off the top of my head.
jklymak commentedon Oct 8, 2017
@dstansby #7811, I think. However, I have no idea if
handles=andlabels=were ever supported. Also please note I edited the comment above as I'd done something silly ;-)dstansby commentedon Oct 8, 2017
According to the
2.0docstring,legend()never accepted handles and labels as kwargs, but instead as normal arguments. If it worked before I guess it was a co-incidence. The2.1docstring also doesn't mention them as kwargs, so I don't think anything is technically wrong, but it seems sensible to support them as kwargs so will leave this open.In the mean time, just dropping
handles=andlabels=should fix the problem.tacaswell commentedon Oct 8, 2017
Because they were named args before, the expectation is that they will work as kwargs as well. This is a regression that should be fixed (and it is a easy fix, just check if they are in kwargs before falling back to searching).
jklymak commentedon Oct 8, 2017
axes.legendallows them to be kwargs as well.axes.legendalso allows just passing one argument, a list of the labels. I'm not sure if we want to do that...I'd fix this, but I don't understand why
handles,labels, andlocaren't still named positional args that default toNone. Do we not like positional arguments?jnothman commentedon Oct 9, 2017
Also makes scikit-learn doc builds fail at https://github.com/scikit-learn/scikit-learn/blob/master/examples/neural_networks/plot_mlp_training_curves.py#L88
jklymak commentedon Oct 10, 2017
See or #9324 for possible fix. However I wouldn’t expect every invocation combination to be respected.
2sn commentedon Oct 11, 2017
Yes, I had looked at the source file rather than the doc and used the names positional arguments from there. I think it is better being able to give them as named arguments that can be passed as keywords so you don't have to remember the order. Explicit is better. Thanks for fixing!
2sn commentedon Oct 11, 2017
PS - I have edited my code to now use positional arguments, but the old behaviour was nicer.