Skip to content

Commit

Permalink
FIX: legend handler warning too liberal
Browse files Browse the repository at this point in the history
  • Loading branch information
jklymak committed Aug 28, 2022
1 parent ddd8fb8 commit 7805ac8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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 comments on commit 7805ac8

Please sign in to comment.