Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e7ffec

Browse files
authored
Merge pull request #10057 from matplotlib/auto-backport-of-pr-10031
Backport PR #10031 on branch v2.1.x
2 parents d83473d + 53c3d4b commit 8e7ffec

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/matplotlib/legend.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from matplotlib import docstring
3838
from matplotlib.artist import Artist, allow_rasterization
3939
from matplotlib.cbook import silent_list, is_hashable
40+
import matplotlib.colors as colors
4041
from matplotlib.font_manager import FontProperties
4142
from matplotlib.lines import Line2D
4243
from 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

Comments
 (0)