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

Skip to content

Commit 0c07515

Browse files
committed
Merge pull request #6366 from anntzer/sort-line-and-image-labels-numerically
ENH: Sort default labels numerically in Qt editor. closes #6315
2 parents 5a7448e + ad4830c commit 0c07515

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/matplotlib/backends/qt_editor/figureoptions.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from matplotlib.externals 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)