37
37
from matplotlib import docstring
38
38
from matplotlib .artist import Artist , allow_rasterization
39
39
from matplotlib .cbook import silent_list , is_hashable
40
+ import matplotlib .colors as colors
40
41
from matplotlib .font_manager import FontProperties
41
42
from matplotlib .lines import Line2D
42
43
from matplotlib .patches import Patch , Rectangle , Shadow , FancyBboxPatch
@@ -1346,7 +1347,7 @@ def _get_legend_handles_labels(axs, legend_handler_map=None):
1346
1347
labels = []
1347
1348
1348
1349
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.
1350
1351
# Consider two handles to be the same if they share a label,
1351
1352
# color, facecolor, and edgecolor.
1352
1353
@@ -1357,17 +1358,20 @@ def _in_handles(h, l):
1357
1358
if type (f_h ) != type (h ):
1358
1359
continue
1359
1360
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 ():
1361
1363
continue
1362
1364
except AttributeError :
1363
1365
pass
1364
1366
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 ():
1366
1369
continue
1367
1370
except AttributeError :
1368
1371
pass
1369
1372
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 ():
1371
1375
continue
1372
1376
except AttributeError :
1373
1377
pass
@@ -1376,9 +1380,9 @@ def _in_handles(h, l):
1376
1380
1377
1381
for handle in _get_legend_handles (axs , legend_handler_map ):
1378
1382
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 )):
1382
1386
handles .append (handle )
1383
1387
labels .append (label )
1384
1388
return handles , labels
0 commit comments