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

Skip to content

Change dictionary to list of tuples to permit duplicate keys #19666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions lib/matplotlib/backends/qt_editor/figureoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,23 @@ def figure_edit(axes, parent=None):

# Sorting for default labels (_lineXXX, _imageXXX).
def cmp_key(label):
match = re.match(r"(_line|_image)(\d+)", label)
"""
Label should be a tuple consisting of the string label,
and the object being sorted by label.
"""
match = re.match(r"(_line|_image)(\d+)", label[0])
if match:
return match.group(1), int(match.group(2))
else:
return label, 0
return label[0], 0

# Get / Curves
linedict = {}
labeled_lines = []
for line in axes.get_lines():
label = line.get_label()
if label == '_nolegend_':
continue
linedict[label] = line
labeled_lines.append((label, line))
curves = []

def prepare_data(d, init):
Expand Down Expand Up @@ -101,9 +105,7 @@ def prepare_data(d, init):
sorted(short2name.items(),
key=lambda short_and_name: short_and_name[1]))

curvelabels = sorted(linedict, key=cmp_key)
for label in curvelabels:
line = linedict[label]
for label, line in sorted(labeled_lines, key=cmp_key):
color = mcolors.to_hex(
mcolors.to_rgba(line.get_color(), line.get_alpha()),
keep_alpha=True)
Expand Down Expand Up @@ -132,17 +134,15 @@ def prepare_data(d, init):
has_curve = bool(curves)

# Get ScalarMappables.
mappabledict = {}
labeled_mappables = []
for mappable in [*axes.images, *axes.collections]:
label = mappable.get_label()
if label == '_nolegend_' or mappable.get_array() is None:
continue
mappabledict[label] = mappable
mappablelabels = sorted(mappabledict, key=cmp_key)
labeled_mappables.append((label, mappable))
mappables = []
cmaps = [(cmap, name) for name, cmap in sorted(cm._cmap_registry.items())]
for label in mappablelabels:
mappable = mappabledict[label]
for label, mappable in sorted(labeled_mappables, key=cmp_key):
cmap = mappable.get_cmap()
if cmap not in cm._cmap_registry.values():
cmaps = [(cmap, cmap.name), *cmaps]
Expand Down Expand Up @@ -205,7 +205,7 @@ def apply_callback(data):

# Set / Curves
for index, curve in enumerate(curves):
line = linedict[curvelabels[index]]
line = labeled_lines[index][1]
(label, linestyle, drawstyle, linewidth, color, marker, markersize,
markerfacecolor, markeredgecolor) = curve
line.set_label(label)
Expand All @@ -223,7 +223,7 @@ def apply_callback(data):

# Set ScalarMappables.
for index, mappable_settings in enumerate(mappables):
mappable = mappabledict[mappablelabels[index]]
mappable = labeled_mappables[index][1]
if len(mappable_settings) == 5:
label, cmap, low, high, interpolation = mappable_settings
mappable.set_interpolation(interpolation)
Expand Down