Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6d9b4a5

Browse filesBrowse files
committed
Sort default labels numerically in Qt editor.
1 parent 21174b5 commit 6d9b4a5
Copy full SHA for 6d9b4a5

File tree

Expand file treeCollapse file tree

1 file changed

+11
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+11
-2
lines changed

‎lib/matplotlib/backends/qt_editor/figureoptions.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/qt_editor/figureoptions.py
+11-2Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import six
1414

1515
import os.path as osp
16+
import re
1617

1718
import matplotlib.backends.qt_editor.formlayout as formlayout
1819
from matplotlib.backends.qt_compat import QtGui
@@ -67,6 +68,14 @@ def figure_edit(axes, parent=None):
6768
xunits = axes.xaxis.get_units()
6869
yunits = axes.yaxis.get_units()
6970

71+
# Sorting for default labels (_lineXXX, _imageXXX).
72+
def cmp_key(label):
73+
match = re.match(r"(_line|_image)(\d+)", label)
74+
if match:
75+
return match.group(1), int(match.group(2))
76+
else:
77+
return label, 0
78+
7079
# Get / Curves
7180
linedict = {}
7281
for line in axes.get_lines():
@@ -100,7 +109,7 @@ def prepare_data(d, init):
100109
sorted(short2name.items(),
101110
key=lambda short_and_name: short_and_name[1]))
102111

103-
curvelabels = sorted(linedict.keys())
112+
curvelabels = sorted(linedict, key=cmp_key)
104113
for label in curvelabels:
105114
line = linedict[label]
106115
color = rgb2hex(colorConverter.to_rgb(line.get_color()))
@@ -131,7 +140,7 @@ def prepare_data(d, init):
131140
if label == '_nolegend_':
132141
continue
133142
imagedict[label] = image
134-
imagelabels = sorted(imagedict)
143+
imagelabels = sorted(imagedict, key=cmp_key)
135144
images = []
136145
cmaps = [(cmap, name) for name, cmap in sorted(cm.cmap_d.items())]
137146
for label in imagelabels:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.