@@ -137,39 +137,43 @@ def prepare_data(d, init):
137
137
# Is there a curve displayed?
138
138
has_curve = bool (curves )
139
139
140
- # Get / Images
141
- imagedict = {}
142
- for image in axes .get_images () :
143
- label = image .get_label ()
140
+ # Get ScalarMappables.
141
+ smdict = {}
142
+ for sm in [ * axes .images , * axes . collections ] :
143
+ label = sm .get_label ()
144
144
if label == '_nolegend_' :
145
145
continue
146
- imagedict [label ] = image
147
- imagelabels = sorted (imagedict , key = cmp_key )
148
- images = []
146
+ smdict [label ] = sm
147
+ smlabels = sorted (smdict , key = cmp_key )
148
+ sms = []
149
149
cmaps = [(cmap , name ) for name , cmap in sorted (cm .cmap_d .items ())]
150
- for label in imagelabels :
151
- image = imagedict [label ]
152
- cmap = image .get_cmap ()
150
+ for label in smlabels :
151
+ sm = smdict [label ]
152
+ cmap = sm .get_cmap ()
153
153
if cmap not in cm .cmap_d .values ():
154
- cmaps = [(cmap , cmap .name )] + cmaps
155
- low , high = image .get_clim ()
156
- imagedata = [
154
+ cmaps = [(cmap , cmap .name ), * cmaps ]
155
+ low , high = sm .get_clim ()
156
+ smdata = [
157
157
('Label' , label ),
158
158
('Colormap' , [cmap .name ] + cmaps ),
159
159
('Min. value' , low ),
160
160
('Max. value' , high ),
161
- ('Interpolation' ,
162
- [image .get_interpolation ()]
163
- + [(name , name ) for name in sorted (mimage .interpolations_names )])]
164
- images .append ([imagedata , label , "" ])
165
- # Is there an image displayed?
166
- has_image = bool (images )
161
+ ]
162
+ if hasattr (sm , "get_interpolation" ): # Images.
163
+ smdata .append ((
164
+ 'Interpolation' ,
165
+ [image .get_interpolation (),
166
+ * ((name , name )
167
+ for name in sorted (mimage .interpolations_names ))]))
168
+ sms .append ([smdata , label , "" ])
169
+ # Is there a scalarmappable displayed?
170
+ has_sm = bool (sms )
167
171
168
172
datalist = [(general , "Axes" , "" )]
169
173
if curves :
170
174
datalist .append ((curves , "Curves" , "" ))
171
- if images :
172
- datalist .append ((images , "Images" , "" ))
175
+ if sms :
176
+ datalist .append ((sms , "Images, etc. " , "" ))
173
177
174
178
def apply_callback (data ):
175
179
"""This function will be called to apply changes"""
@@ -178,7 +182,7 @@ def apply_callback(data):
178
182
179
183
general = data .pop (0 )
180
184
curves = data .pop (0 ) if has_curve else []
181
- images = data .pop (0 ) if has_image else []
185
+ sms = data .pop (0 ) if has_sm else []
182
186
if data :
183
187
raise ValueError ("Unexpected field" )
184
188
@@ -223,14 +227,20 @@ def apply_callback(data):
223
227
line .set_markerfacecolor (markerfacecolor )
224
228
line .set_markeredgecolor (markeredgecolor )
225
229
226
- # Set / Images
227
- for index , image_settings in enumerate (images ):
228
- image = imagedict [imagelabels [index ]]
229
- label , cmap , low , high , interpolation = image_settings
230
- image .set_label (label )
231
- image .set_cmap (cm .get_cmap (cmap ))
232
- image .set_clim (* sorted ([low , high ]))
233
- image .set_interpolation (interpolation )
230
+ # Set ScalarMappables.
231
+ for index , sm_settings in enumerate (sms ):
232
+ sm = smdict [smlabels [index ]]
233
+ sentinel = object ()
234
+ if len (sm_settings ) == 5 :
235
+ label , cmap , low , high , interpolation = sm_settings
236
+ elif len (sm_settings ) == 4 :
237
+ label , cmap , low , high = sm_settings
238
+ interpolation = sentinel
239
+ sm .set_label (label )
240
+ sm .set_cmap (cm .get_cmap (cmap ))
241
+ sm .set_clim (* sorted ([low , high ]))
242
+ if interpolation is not sentinel :
243
+ sm .set_interpolation (interpolation )
234
244
235
245
# re-generate legend, if checkbox is checked
236
246
if generate_legend :
0 commit comments