@@ -59,19 +59,23 @@ def figure_edit(axes, parent=None):
59
59
60
60
# Sorting for default labels (_lineXXX, _imageXXX).
61
61
def cmp_key (label ):
62
- match = re .match (r"(_line|_image)(\d+)" , label )
62
+ """
63
+ Label should be a tuple consisting of the string label,
64
+ and the object being sorted by label.
65
+ """
66
+ match = re .match (r"(_line|_image)(\d+)" , label [0 ])
63
67
if match :
64
68
return match .group (1 ), int (match .group (2 ))
65
69
else :
66
- return label , 0
70
+ return label [ 0 ] , 0
67
71
68
72
# Get / Curves
69
- linedict = {}
73
+ labeled_lines = []
70
74
for line in axes .get_lines ():
71
75
label = line .get_label ()
72
76
if label == '_nolegend_' :
73
77
continue
74
- linedict [ label ] = line
78
+ labeled_lines . append (( label , line ))
75
79
curves = []
76
80
77
81
def prepare_data (d , init ):
@@ -101,9 +105,7 @@ def prepare_data(d, init):
101
105
sorted (short2name .items (),
102
106
key = lambda short_and_name : short_and_name [1 ]))
103
107
104
- curvelabels = sorted (linedict , key = cmp_key )
105
- for label in curvelabels :
106
- line = linedict [label ]
108
+ for label , line in sorted (labeled_lines , key = cmp_key ):
107
109
color = mcolors .to_hex (
108
110
mcolors .to_rgba (line .get_color (), line .get_alpha ()),
109
111
keep_alpha = True )
@@ -132,17 +134,15 @@ def prepare_data(d, init):
132
134
has_curve = bool (curves )
133
135
134
136
# Get ScalarMappables.
135
- mappabledict = {}
137
+ labeled_mappables = []
136
138
for mappable in [* axes .images , * axes .collections ]:
137
139
label = mappable .get_label ()
138
140
if label == '_nolegend_' or mappable .get_array () is None :
139
141
continue
140
- mappabledict [label ] = mappable
141
- mappablelabels = sorted (mappabledict , key = cmp_key )
142
+ labeled_mappables .append ((label , mappable ))
142
143
mappables = []
143
144
cmaps = [(cmap , name ) for name , cmap in sorted (cm ._cmap_registry .items ())]
144
- for label in mappablelabels :
145
- mappable = mappabledict [label ]
145
+ for label , mappable in sorted (labeled_mappables , key = cmp_key ):
146
146
cmap = mappable .get_cmap ()
147
147
if cmap not in cm ._cmap_registry .values ():
148
148
cmaps = [(cmap , cmap .name ), * cmaps ]
@@ -205,7 +205,7 @@ def apply_callback(data):
205
205
206
206
# Set / Curves
207
207
for index , curve in enumerate (curves ):
208
- line = linedict [ curvelabels [ index ]]
208
+ line = labeled_lines [ index ][ 1 ]
209
209
(label , linestyle , drawstyle , linewidth , color , marker , markersize ,
210
210
markerfacecolor , markeredgecolor ) = curve
211
211
line .set_label (label )
@@ -223,7 +223,7 @@ def apply_callback(data):
223
223
224
224
# Set ScalarMappables.
225
225
for index , mappable_settings in enumerate (mappables ):
226
- mappable = mappabledict [ mappablelabels [ index ]]
226
+ mappable = labeled_mappables [ index ][ 1 ]
227
227
if len (mappable_settings ) == 5 :
228
228
label , cmap , low , high , interpolation = mappable_settings
229
229
mappable .set_interpolation (interpolation )
0 commit comments