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):
465465 _lab , _hand = [], []
466466 for label , handle in zip (labels , handles ):
467467 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('_')]`." ))
471474 else :
472475 _lab .append (label )
473476 _hand .append (handle )
Original file line number Diff line number Diff line change 1717import matplotlib .lines as mlines
1818from matplotlib .legend_handler import HandlerTuple
1919import matplotlib .legend as mlegend
20- from matplotlib import rc_context
20+ from matplotlib import _api , rc_context
2121from matplotlib .font_manager import FontProperties
2222
2323
@@ -144,8 +144,7 @@ def test_legend_label_with_leading_underscore():
144144 """
145145 fig , ax = plt .subplots ()
146146 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" ):
149148 legend = ax .legend (handles = [line ])
150149 assert len (legend .legend_handles ) == 0
151150
You can’t perform that action at this time.
0 commit comments