From ad4830ccceff073e0cd332df20d8158d10c8fcdc Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 4 May 2016 17:37:46 -0700 Subject: [PATCH] Sort default labels numerically in Qt editor. --- lib/matplotlib/backends/qt_editor/figureoptions.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backends/qt_editor/figureoptions.py b/lib/matplotlib/backends/qt_editor/figureoptions.py index c044979dee96..9285257ed2ba 100644 --- a/lib/matplotlib/backends/qt_editor/figureoptions.py +++ b/lib/matplotlib/backends/qt_editor/figureoptions.py @@ -13,6 +13,7 @@ from matplotlib.externals import six import os.path as osp +import re import matplotlib.backends.qt_editor.formlayout as formlayout from matplotlib.backends.qt_compat import QtGui @@ -67,6 +68,14 @@ def figure_edit(axes, parent=None): xunits = axes.xaxis.get_units() yunits = axes.yaxis.get_units() + # Sorting for default labels (_lineXXX, _imageXXX). + def cmp_key(label): + match = re.match(r"(_line|_image)(\d+)", label) + if match: + return match.group(1), int(match.group(2)) + else: + return label, 0 + # Get / Curves linedict = {} for line in axes.get_lines(): @@ -100,7 +109,7 @@ def prepare_data(d, init): sorted(short2name.items(), key=lambda short_and_name: short_and_name[1])) - curvelabels = sorted(linedict.keys()) + curvelabels = sorted(linedict, key=cmp_key) for label in curvelabels: line = linedict[label] color = rgb2hex(colorConverter.to_rgb(line.get_color())) @@ -131,7 +140,7 @@ def prepare_data(d, init): if label == '_nolegend_': continue imagedict[label] = image - imagelabels = sorted(imagedict) + imagelabels = sorted(imagedict, key=cmp_key) images = [] cmaps = [(cmap, name) for name, cmap in sorted(cm.cmap_d.items())] for label in imagelabels: