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
@@ -1325,7 +1326,7 @@ def _get_legend_handles_labels(axs, legend_handler_map=None):
1325
1326
labels = []
1326
1327
1327
1328
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.
1329
1330
# Consider two handles to be the same if they share a label,
1330
1331
# color, facecolor, and edgecolor.
1331
1332
@@ -1336,17 +1337,20 @@ def _in_handles(h, l):
1336
1337
if type (f_h ) != type (h ):
1337
1338
continue
1338
1339
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 ():
1340
1342
continue
1341
1343
except AttributeError :
1342
1344
pass
1343
1345
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 ():
1345
1348
continue
1346
1349
except AttributeError :
1347
1350
pass
1348
1351
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 ():
1350
1354
continue
1351
1355
except AttributeError :
1352
1356
pass
@@ -1355,9 +1359,9 @@ def _in_handles(h, l):
1355
1359
1356
1360
for handle in _get_legend_handles (axs , legend_handler_map ):
1357
1361
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 )):
1361
1365
handles .append (handle )
1362
1366
labels .append (label )
1363
1367
return handles , labels
0 commit comments