Skip to content

VIS Wrong legend when combining multiple plots on the same axes , plotting with legend=False messes up legend #40046

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

Closed
wants to merge 2 commits into from

Conversation

MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented Feb 25, 2021

So, in #27808 , leg.legendHandles was replaced with ax.get_legend_handles_labels()[0] in order to preserve marker info.

However, ax.get_legend_handles_labels()[0] may contain extra elements which aren't (yet) visible, which means we may end up at

ax.legend(handles, labels, loc="best", title=title)

with

(Pdb) handles
[<matplotlib.lines.Line2D object at 0x7f0938a37430>, <ErrorbarContainer object of 3 artists>, <matplotlib.lines.Line2D object at 0x7f0938a37430>]
(Pdb) labels
['orange', 'blue']

This causes the permuting noted in #39522

Ideally, there would be a way to get leg.legendHandles in a way that preserves the marker info. However, I can't find a way to do that - have asked on the matplotlib discourse. Also, the current test doesn't quite work (as it passes on master too). I'm working on finding a satisfactory solution


On master:

image

On this branch:

image


cc @charlesdong1991 in case you have comments / suggestions

@MarcoGorelli
Copy link
Member Author

closing as I'm not happy with this solution - will get back to it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant