8000 FIX: legend handler warning too liberal by jklymak · Pull Request #23762 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX: legend handler warning too liberal #23762

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 1 commit into from
Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ def _get_legend_handles(axs, legend_handler_map=None):
label = handle.get_label()
if label != '_nolegend_' and has_handler(handler_map, handle):
yield handle
elif (label not in ['_nolegend_', ''] and
elif (label and not label.startswith('_') and
not has_handler(handler_map, handle)):
_api.warn_external(
"Legend does not support handles for {0} "
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import collections
import platform
from unittest import mock
import warnings

import numpy as np
import pytest
Expand Down Expand Up @@ -515,6 +516,13 @@ def test_text_nohandler_warning():
ax.legend()
assert len(record) == 1

# this should _not_ warn:
f, ax = plt.subplots()
ax.pcolormesh(np.random.uniform(0, 1, (10, 10)))
with warnings.catch_warnings():
warnings.simplefilter("error")
ax.get_legend_handles_labels()


def test_empty_bar_chart_with_legend():
"""Test legend when bar chart is empty with a label."""
Expand Down
0