Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d357921

Browse filesBrowse files
tacaswellmeeseeksmachine
authored andcommitted
Backport PR #23762: FIX: legend handler warning too liberal
1 parent be04a59 commit d357921
Copy full SHA for d357921

File tree

Expand file treeCollapse file tree

2 files changed

+9
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-1
lines changed

‎lib/matplotlib/legend.py

Copy file name to clipboardExpand all lines: lib/matplotlib/legend.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ def _get_legend_handles(axs, legend_handler_map=None):
11401140
label = handle.get_label()
11411141
if label != '_nolegend_' and has_handler(handler_map, handle):
11421142
yield handle
1143-
elif (label not in ['_nolegend_', ''] and
1143+
elif (label and not label.startswith('_') and
11441144
not has_handler(handler_map, handle)):
11451145
_api.warn_external(
11461146
"Legend does not support handles for {0} "

‎lib/matplotlib/tests/test_legend.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_legend.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import collections
22
import platform
33
from unittest import mock
4+
import warnings
45

56
import numpy as np
67
import pytest
@@ -515,6 +516,13 @@ def test_text_nohandler_warning():
515516
ax.legend()
516517
assert len(record) == 1
517518

519+
# this should _not_ warn:
520+
f, ax = plt.subplots()
521+
ax.pcolormesh(np.random.uniform(0, 1, (10, 10)))
522+
with warnings.catch_warnings():
523+
warnings.simplefilter("error")
524+
ax.get_legend_handles_labels()
525+
518526

519527
def test_empty_bar_chart_with_legend():
520528
"""Test legend when bar chart is empty with a label."""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.