Skip to content

Commit ab0d32f

Browse files
committed
Change dictionary to list of tuples to permit duplicate keys
1 parent 71c9f09 commit ab0d32f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/matplotlib/backends/qt_editor/figureoptions.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,21 @@ def figure_edit(axes, parent=None):
5959

6060
# Sorting for default labels (_lineXXX, _imageXXX).
6161
def cmp_key(label):
62+
if type(label) == tuple:
63+
label = label[0]
6264
match = re.match(r"(_line|_image)(\d+)", label)
6365
if match:
6466
return match.group(1), int(match.group(2))
6567
else:
6668
return label, 0
6769

6870
# Get / Curves
69-
linedict = {}
71+
labeled_lines = []
7072
for line in axes.get_lines():
7173
label = line.get_label()
7274
if label == '_nolegend_':
7375
continue
74-
linedict[label] = line
76+
labeled_lines.append((label, line))
7577
curves = []
7678

7779
def prepare_data(d, init):
@@ -101,9 +103,9 @@ def prepare_data(d, init):
101103
sorted(short2name.items(),
102104
key=lambda short_and_name: short_and_name[1]))
103105

104-
curvelabels = sorted(linedict, key=cmp_key)
105-
for label in curvelabels:
106-
line = linedict[label]
106+
sorted_labels_and_curves = sorted(labeled_lines, key=cmp_key)
107+
108+
for label, line in sorted_labels_and_curves:
107109
color = mcolors.to_hex(
108110
mcolors.to_rgba(line.get_color(), line.get_alpha()),
109111
keep_alpha=True)
@@ -205,7 +207,7 @@ def apply_callback(data):
205207

206208
# Set / Curves
207209
for index, curve in enumerate(curves):
208-
line = linedict[curvelabels[index]]
210+
line = labeled_lines[index][1]
209211
(label, linestyle, drawstyle, linewidth, color, marker, markersize,
210212
markerfacecolor, markeredgecolor) = curve
211213
line.set_label(label)

0 commit comments

Comments
 (0)