Skip to content

Commit 9622598

Browse files
committed
Stop sorting artists in Figure Options dialog
With #18216, the order that artists are added to an Axes is their canonical order. The dialog should not be sorting them in some other manner. Additionally, this fixes a bug in that `apply_callback` indexes back to the original list, which means that changes will be made to the *wrong* artist if sorting actually occurred. It also makes the legend almost entirely wrong as well. See https://discourse.matplotlib.org/t/bug-on-re-generate-automatic-legend-of-matplotlib-figure-property/22511
1 parent eaadeb6 commit 9622598

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

lib/matplotlib/backends/qt_editor/figureoptions.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
"""Module that provides a GUI-based editor for Matplotlib's figure options."""
77

8-
import re
9-
108
from matplotlib import cbook, cm, colors as mcolors, markers, image as mimage
119
from matplotlib.backends.qt_compat import QtGui
1210
from matplotlib.backends.qt_editor import _formlayout
@@ -65,18 +63,6 @@ def convert_limits(lim, converter):
6563
xunits = axes.xaxis.get_units()
6664
yunits = axes.yaxis.get_units()
6765

68-
# Sorting for default labels (_lineXXX, _imageXXX).
69-
def cmp_key(label):
70-
"""
71-
Label should be a tuple consisting of the string label,
72-
and the object being sorted by label.
73-
"""
74-
match = re.match(r"(_line|_image)(\d+)", label[0])
75-
if match:
76-
return match.group(1), int(match.group(2))
77-
else:
78-
return label[0], 0
79-
8066
# Get / Curves
8167
labeled_lines = []
8268
for line in axes.get_lines():
@@ -113,7 +99,7 @@ def prepare_data(d, init):
11399
sorted(short2name.items(),
114100
key=lambda short_and_name: short_and_name[1]))
115101

116-
for label, line in sorted(labeled_lines, key=cmp_key):
102+
for label, line in labeled_lines:
117103
color = mcolors.to_hex(
118104
mcolors.to_rgba(line.get_color(), line.get_alpha()),
119105
keep_alpha=True)
@@ -150,7 +136,7 @@ def prepare_data(d, init):
150136
labeled_mappables.append((label, mappable))
151137
mappables = []
152138
cmaps = [(cmap, name) for name, cmap in sorted(cm._cmap_registry.items())]
153-
for label, mappable in sorted(labeled_mappables, key=cmp_key):
139+
for label, mappable in labeled_mappables:
154140
cmap = mappable.get_cmap()
155141
if cmap not in cm._cmap_registry.values():
156142
cmaps = [(cmap, cmap.name), *cmaps]

0 commit comments

Comments
 (0)