Skip to content
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

[Bug]: False positive legend handler warnings in 3.6.0.rc1 #23761

Closed
mwaskom opened this issue Aug 27, 2022 · 2 comments · Fixed by #23762
Closed

[Bug]: False positive legend handler warnings in 3.6.0.rc1 #23761

mwaskom opened this issue Aug 27, 2022 · 2 comments · Fixed by #23762
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Milestone

Comments

@mwaskom
Copy link

mwaskom commented Aug 27, 2022

Bug summary

With the 3.6.0.rc1, matplotlib is issuing warnings when preparing a legend if the axes contains artists that do not have a registered legend handler even if the artist was not provided with a label.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

f, ax = plt.subplots()
ax.pcolormesh(np.random.uniform(0, 1, (10, 10)))
ax.get_legend_handles_labels()

Actual outcome

Warning:

/var/folders/pk/kq0vw6sj3ssd914z55j1qmzc0000gn/T/ipykernel_68178/1573363929.py:6: UserWarning: Legend does not support handles for QuadMesh instances.
See: https://matplotlib.org/stable/tutorials/intermediate/legend_guide.html#implementing-a-custom-legend-handler
  ax.get_legend_handles_labels()

Expected outcome

This was not previously so noisy.

Additional information

I skimmed the existing issues and didn't see anything obviously reporting this, but haven't tried against main so apologies if this is a dupe.

Matplotlib Version

3.6.0.rc1

@jklymak
Copy link
Member

jklymak commented Aug 27, 2022

This was broken by #20470. This check should be bypassed if label is '' or 'nolegend', but for some reason the label here is _child0, which is done in ax.add_collection. I think the fix is straight forwardly to skip any legends that start with _ in this check.

@jklymak jklymak added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Aug 27, 2022
@jklymak jklymak added this to the v3.6.0 milestone Aug 27, 2022
@jklymak
Copy link
Member

jklymak commented Aug 27, 2022

If you have the inclination, you could make sure #23762 fixes it in your real code...

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 a pull request may close this issue.

2 participants