File tree Expand file tree Collapse file tree 3 files changed +15
-6
lines changed
doc/api/next_api_changes/deprecations Expand file tree Collapse file tree 3 files changed +15
-6
lines changed Original file line number Diff line number Diff line change
1
+ Artists explicitly passed in will no longer be filtered by legend() based on their label
2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3
+ Currently, artists explicitly passed to ``legend(handles=[...]) `` are filtered
4
+ out if their label starts with an underscore. This behavior is deprecated;
5
+ explicitly filter out such artists
6
+ (``[art for art in artists if not art.get_label().startswith('_')] ``) if
7
+ necessary.
Original file line number Diff line number Diff line change @@ -465,9 +465,12 @@ def val_or_rc(val, rc_name):
465
465
_lab , _hand = [], []
466
466
for label , handle in zip (labels , handles ):
467
467
if isinstance (label , str ) and label .startswith ('_' ):
468
- _api .warn_external (f"The label { label !r} of { handle !r} starts "
469
- "with '_'. It is thus excluded from the "
470
- "legend." )
468
+ _api .warn_deprecated ("3.8" , message = (
469
+ "An artist whose label starts with an underscore was passed to "
470
+ "legend(); such artists will no longer be ignored in the future. "
471
+ "To suppress this warning, explicitly filter out such artists, "
472
+ "e.g. with `[art for art in artists if not "
473
+ "art.get_label().startswith('_')]`." ))
471
474
else :
472
475
_lab .append (label )
473
476
_hand .append (handle )
Original file line number Diff line number Diff line change 17
17
import matplotlib .lines as mlines
18
18
from matplotlib .legend_handler import HandlerTuple
19
19
import matplotlib .legend as mlegend
20
- from matplotlib import rc_context
20
+ from matplotlib import _api , rc_context
21
21
from matplotlib .font_manager import FontProperties
22
22
23
23
@@ -144,8 +144,7 @@ def test_legend_label_with_leading_underscore():
144
144
"""
145
145
fig , ax = plt .subplots ()
146
146
line , = ax .plot ([0 , 1 ], label = '_foo' )
147
- with pytest .warns (UserWarning ,
148
- match = r"starts with '_'.*excluded from the legend." ):
147
+ with pytest .warns (_api .MatplotlibDeprecationWarning , match = "with an underscore" ):
149
148
legend = ax .legend (handles = [line ])
150
149
assert len (legend .legend_handles ) == 0
151
150
You can’t perform that action at this time.
0 commit comments