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 (
@@ -748,11 +749,12 @@ def _init_legend_box(self, handles, labels, markerfirst=True):
748
749
handler = self .get_legend_handler (legend_handler_map , orig_handle )
749
750
if handler is None :
750
751
_api .warn_external (
751
- "Legend does not support {!r} instances.\n A proxy artist "
752
- "may be used instead.\n See: "
753
- "https://matplotlib.org/users/legend_guide.html"
754
- "#creating-artists-specifically-for-adding-to-the-legend-"
755
- "aka-proxy-artists" .format (orig_handle ))
752
+ "Legend does not support handles for {0} "
753
+ "instances.\n A proxy artist may be used "
754
+ "instead.\n See: https://matplotlib.org/"
755
+ "stable/tutorials/intermediate/legend_guide.html"
756
+ "#controlling-the-legend-entries" .format (
757
+ type (orig_handle ).__name__ ))
756
758
# We don't have a handle for this artist, so we just defer
757
759
# to None.
758
760
handle_list .append (None )
@@ -1102,14 +1104,14 @@ def _get_legend_handles(axs, legend_handler_map=None):
1102
1104
for ax in axs :
1103
1105
handles_original += [
1104
1106
* (a for a in ax ._children
1105
- if isinstance (a , (Line2D , Patch , Collection ))),
1107
+ if isinstance (a , (Line2D , Patch , Collection , Text ))),
1106
1108
* ax .containers ]
1107
1109
# support parasite axes:
1108
1110
if hasattr (ax , 'parasites' ):
1109
1111
for axx in ax .parasites :
1110
1112
handles_original += [
1111
1113
* (a for a in axx ._children
1112
- if isinstance (a , (Line2D , Patch , Collection ))),
1114
+ if isinstance (a , (Line2D , Patch , Collection , Text ))),
1113
1115
* axx .containers ]
1114
1116
1115
1117
handler_map = {** Legend .get_default_handler_map (),
@@ -1119,6 +1121,14 @@ def _get_legend_handles(axs, legend_handler_map=None):
1119
1121
label = handle .get_label ()
1120
1122
if label != '_nolegend_' and has_handler (handler_map , handle ):
1121
1123
yield handle
1124
+ elif not has_handler (handler_map , handle ):
1125
+ _api .warn_external (
1126
+ "Legend does not support handles for {0} "
1127
+ "instances.\n See: https://matplotlib.org/stable/"
1128
+ "tutorials/intermediate/legend_guide.html"
1129
+ "#implementing-a-custom-legend-handler" .format (
1130
+ type (handle ).__name__ ))
1131
+ continue
1122
1132
1123
1133
1124
1134
def _get_legend_handles_labels (axs , legend_handler_map = None ):
0 commit comments