3737from matplotlib import docstring
3838from matplotlib .artist import Artist , allow_rasterization
3939from matplotlib .cbook import silent_list , is_hashable
40+ import matplotlib .colors as colors
4041from matplotlib .font_manager import FontProperties
4142from matplotlib .lines import Line2D
4243from matplotlib .patches import Patch , Rectangle , Shadow , FancyBboxPatch
@@ -1346,7 +1347,7 @@ def _get_legend_handles_labels(axs, legend_handler_map=None):
13461347 labels = []
13471348
13481349 def _in_handles (h , l ):
1349- # Method to check if we already have a given handle and label.
1350+ # Method to check if we already have a given handle and label.
13501351 # Consider two handles to be the same if they share a label,
13511352 # color, facecolor, and edgecolor.
13521353
@@ -1357,17 +1358,20 @@ def _in_handles(h, l):
13571358 if type (f_h ) != type (h ):
13581359 continue
13591360 try :
1360- if f_h .get_color () != h .get_color ():
1361+ if (colors .to_rgba_array (f_h .get_color ()) !=
1362+ colors .to_rgba_array (h .get_color ())).any ():
13611363 continue
13621364 except AttributeError :
13631365 pass
13641366 try :
1365- if f_h .get_facecolor () != h .get_facecolor ():
1367+ if (colors .to_rgba_array (f_h .get_facecolor ()) !=
1368+ colors .to_rgba_array (h .get_facecolor ())).any ():
13661369 continue
13671370 except AttributeError :
13681371 pass
13691372 try :
1370- if f_h .get_edgecolor () != h .get_edgecolor ():
1373+ if (colors .to_rgba_array (f_h .get_edgecolor ()) !=
1374+ colors .to_rgba_array (h .get_edgecolor ())).any ():
13711375 continue
13721376 except AttributeError :
13731377 pass
@@ -1376,9 +1380,9 @@ def _in_handles(h, l):
13761380
13771381 for handle in _get_legend_handles (axs , legend_handler_map ):
13781382 label = handle .get_label ()
1379- if (label
1380- and not label .startswith ('_' )
1381- and not _in_handles (handle , label )):
1383+ if (label and
1384+ not label .startswith ('_' ) and
1385+ not _in_handles (handle , label )):
13821386 handles .append (handle )
13831387 labels .append (label )
13841388 return handles , labels
0 commit comments