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
@@ -1339,7 +1340,7 @@ def _get_legend_handles_labels(axs, legend_handler_map=None):
1339
1340
labels = []
1340
1341
1341
1342
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.
1343
1344
# Consider two handles to be the same if they share a label,
1344
1345
# color, facecolor, and edgecolor.
1345
1346
@@ -1350,17 +1351,20 @@ def _in_handles(h, l):
1350
1351
if type (f_h ) != type (h ):
1351
1352
continue
1352
1353
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 ())):
1354
1356
continue
1355
1357
except AttributeError :
1356
1358
pass
1357
1359
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 ())):
1359
1362
continue
1360
1363
except AttributeError :
1361
1364
pass
1362
1365
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 ())):
1364
1368
continue
1365
1369
except AttributeError :
1366
1370
pass
@@ -1369,9 +1373,9 @@ def _in_handles(h, l):
1369
1373
1370
1374
for handle in _get_legend_handles (axs , legend_handler_map ):
1371
1375
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 )):
1375
1379
handles .append (handle )
1376
1380
labels .append (label )
1377
1381
return handles , labels
0 commit comments