38
38
from matplotlib .collections import (
39
39
Collection , CircleCollection , LineCollection , PathCollection ,
40
40
PolyCollection , RegularPolyCollection )
41
+ from matplotlib .text import Text
41
42
from matplotlib .transforms import Bbox , BboxBase , TransformedBbox
42
43
from matplotlib .transforms import BboxTransformTo , BboxTransformFrom
43
44
from matplotlib .offsetbox import (
@@ -740,11 +741,12 @@ def _init_legend_box(self, handles, labels, markerfirst=True):
740
741
handler = self .get_legend_handler (legend_handler_map , orig_handle )
741
742
if handler is None :
742
743
_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__ ))
748
750
# No handle for this artist, so we just defer to None.
749
751
handle_list .append (None )
750
752
else :
@@ -1074,14 +1076,14 @@ def _get_legend_handles(axs, legend_handler_map=None):
1074
1076
for ax in axs :
1075
1077
handles_original += [
1076
1078
* (a for a in ax ._children
1077
- if isinstance (a , (Line2D , Patch , Collection ))),
1079
+ if isinstance (a , (Line2D , Patch , Collection , Text ))),
1078
1080
* ax .containers ]
1079
1081
# support parasite axes:
1080
1082
if hasattr (ax , 'parasites' ):
1081
1083
for axx in ax .parasites :
1082
1084
handles_original += [
1083
1085
* (a for a in axx ._children
1084
- if isinstance (a , (Line2D , Patch , Collection ))),
1086
+ if isinstance (a , (Line2D , Patch , Collection , Text ))),
1085
1087
* axx .containers ]
1086
1088
1087
1089
handler_map = {** Legend .get_default_handler_map (),
@@ -1091,6 +1093,15 @@ def _get_legend_handles(axs, legend_handler_map=None):
1091
1093
label = handle .get_label ()
1092
1094
if label != '_nolegend_' and has_handler (handler_map , handle ):
1093
1095
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
1094
1105
1095
1106
1096
1107
def _get_legend_handles_labels (axs , legend_handler_map = None ):
0 commit comments