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
@@ -1339,7 +1340,7 @@ def _get_legend_handles_labels(axs, legend_handler_map=None):
13391340 labels = []
13401341
13411342 def _in_handles (h , l ):
1342- # Method to check if we already have a given handle and label.
1343+ # Method to check if we already have a given handle and label.
13431344 # Consider two handles to be the same if they share a label,
13441345 # color, facecolor, and edgecolor.
13451346
@@ -1350,17 +1351,20 @@ def _in_handles(h, l):
13501351 if type (f_h ) != type (h ):
13511352 continue
13521353 try :
1353- if (f_h .get_color () != h .get_color ()).any ():
1354+ if (colors .to_rgba (f_h .get_color ()) !=
1355+ colors .to_rgba (h .get_color ())):
13541356 continue
13551357 except AttributeError :
13561358 pass
13571359 try :
1358- if (f_h .get_facecolor () != h .get_facecolor ()).any ():
1360+ if (colors .to_rgba (f_h .get_facecolor ()) !=
1361+ colors .to_rgba (h .get_facecolor ())):
13591362 continue
13601363 except AttributeError :
13611364 pass
13621365 try :
1363- if (f_h .get_edgecolor () != h .get_edgecolor ()).any ():
1366+ if (colors .to_rgba (f_h .get_edgecolor ()) !=
1367+ colors .to_rgba (h .get_edgecolor ())):
13641368 continue
13651369 except AttributeError :
13661370 pass
@@ -1369,9 +1373,9 @@ def _in_handles(h, l):
13691373
13701374 for handle in _get_legend_handles (axs , legend_handler_map ):
13711375 label = handle .get_label ()
1372- if (label
1373- and not label .startswith ('_' )
1374- and not _in_handles (handle , label )):
1376+ if (label and
1377+ not label .startswith ('_' ) and
1378+ not _in_handles (handle , label )):
13751379 handles .append (handle )
13761380 labels .append (label )
13771381 return handles , labels
0 commit comments