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
@@ -1325,7 +1326,7 @@ def _get_legend_handles_labels(axs, legend_handler_map=None):
13251326 labels = []
13261327
13271328 def _in_handles (h , l ):
1328- # Method to check if we already have a given handle and label.
1329+ # Method to check if we already have a given handle and label.
13291330 # Consider two handles to be the same if they share a label,
13301331 # color, facecolor, and edgecolor.
13311332
@@ -1336,17 +1337,20 @@ def _in_handles(h, l):
13361337 if type (f_h ) != type (h ):
13371338 continue
13381339 try :
1339- if f_h .get_color () != h .get_color ():
1340+ if (colors .to_rgba_array (f_h .get_color ()) !=
1341+ colors .to_rgba_array (h .get_color ())).any ():
13401342 continue
13411343 except AttributeError :
13421344 pass
13431345 try :
1344- if f_h .get_facecolor () != h .get_facecolor ():
1346+ if (colors .to_rgba_array (f_h .get_facecolor ()) !=
1347+ colors .to_rgba_array (h .get_facecolor ())).any ():
13451348 continue
13461349 except AttributeError :
13471350 pass
13481351 try :
1349- if f_h .get_edgecolor () != h .get_edgecolor ():
1352+ if (colors .to_rgba_array (f_h .get_edgecolor ()) !=
1353+ colors .to_rgba_array (h .get_edgecolor ())).any ():
13501354 continue
13511355 except AttributeError :
13521356 pass
@@ -1355,9 +1359,9 @@ def _in_handles(h, l):
13551359
13561360 for handle in _get_legend_handles (axs , legend_handler_map ):
13571361 label = handle .get_label ()
1358- if (label
1359- and not label .startswith ('_' )
1360- and not _in_handles (handle , label )):
1362+ if (label and
1363+ not label .startswith ('_' ) and
1364+ not _in_handles (handle , label )):
13611365 handles .append (handle )
13621366 labels .append (label )
13631367 return handles , labels
0 commit comments