3838from matplotlib .collections import (
3939 Collection , CircleCollection , LineCollection , PathCollection ,
4040 PolyCollection , RegularPolyCollection )
41+ from matplotlib .text import Text
4142from matplotlib .transforms import Bbox , BboxBase , TransformedBbox
4243from matplotlib .transforms import BboxTransformTo , BboxTransformFrom
4344from matplotlib .offsetbox import (
@@ -740,11 +741,12 @@ def _init_legend_box(self, handles, labels, markerfirst=True):
740741 handler = self .get_legend_handler (legend_handler_map , orig_handle )
741742 if handler is None :
742743 _api .warn_external (
743- "Legend does not support {!r} instances.\n A proxy artist "
744- "may be used instead.\n See: "
745- "https://matplotlib.org/users/legend_guide.html"
746- "#creating-artists-specifically-for-adding-to-the-legend-"
747- "aka-proxy-artists" .format (orig_handle ))
744+ "Legend does not support handles for {0} "
745+ "instances.\n A proxy artist may be used "
746+ "instead.\n See: https://matplotlib.org/"
747+ "stable/tutorials/intermediate/legend_guide.html"
748+ "#controlling-the-legend-entries" .format (
749+ type (orig_handle ).__name__ ))
748750 # No handle for this artist, so we just defer to None.
749751 handle_list .append (None )
750752 else :
@@ -1074,14 +1076,14 @@ def _get_legend_handles(axs, legend_handler_map=None):
10741076 for ax in axs :
10751077 handles_original += [
10761078 * (a for a in ax ._children
1077- if isinstance (a , (Line2D , Patch , Collection ))),
1079+ if isinstance (a , (Line2D , Patch , Collection , Text ))),
10781080 * ax .containers ]
10791081 # support parasite axes:
10801082 if hasattr (ax , 'parasites' ):
10811083 for axx in ax .parasites :
10821084 handles_original += [
10831085 * (a for a in axx ._children
1084- if isinstance (a , (Line2D , Patch , Collection ))),
1086+ if isinstance (a , (Line2D , Patch , Collection , Text ))),
10851087 * axx .containers ]
10861088
10871089 handler_map = {** Legend .get_default_handler_map (),
@@ -1091,6 +1093,15 @@ def _get_legend_handles(axs, legend_handler_map=None):
10911093 label = handle .get_label ()
10921094 if label != '_nolegend_' and has_handler (handler_map , handle ):
10931095 yield handle
1096+ elif (label not in ['_nolegend_' , '' ] and
1097+ not has_handler (handler_map , handle )):
1098+ _api .warn_external (
1099+ "Legend does not support handles for {0} "
1100+ "instances.\n See: https://matplotlib.org/stable/"
1101+ "tutorials/intermediate/legend_guide.html"
1102+ "#implementing-a-custom-legend-handler" .format (
1103+ type (handle ).__name__ ))
1104+ continue
10941105
10951106
10961107def _get_legend_handles_labels (axs , legend_handler_map = None ):
0 commit comments