@@ -137,39 +137,43 @@ def prepare_data(d, init):
137137 # Is there a curve displayed?
138138 has_curve = bool (curves )
139139
140- # Get / Images
141- imagedict = {}
142- for image in axes .get_images () :
143- label = image .get_label ()
144- if label == '_nolegend_' :
140+ # Get ScalarMappables.
141+ mappabledict = {}
142+ for mappable in [ * axes .images , * axes . collections ] :
143+ label = mappable .get_label ()
144+ if label == '_nolegend_' or mappable . get_array () is None :
145145 continue
146- imagedict [label ] = image
147- imagelabels = sorted (imagedict , key = cmp_key )
148- images = []
146+ mappabledict [label ] = mappable
147+ mappablelabels = sorted (mappabledict , key = cmp_key )
148+ mappables = []
149149 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 mappablelabels :
151+ mappable = mappabledict [label ]
152+ cmap = mappable .get_cmap ()
153153 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 = mappable .get_clim ()
156+ mappabledata = [
157157 ('Label' , label ),
158158 ('Colormap' , [cmap .name ] + cmaps ),
159159 ('Min. value' , low ),
160160 ('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 (mappable , "get_interpolation" ): # Images.
163+ interpolations = [
164+ (name , name ) for name in sorted (mimage .interpolations_names )]
165+ mappabledata .append ((
166+ 'Interpolation' ,
167+ [mappable .get_interpolation (), * interpolations ]))
168+ mappables .append ([mappabledata , label , "" ])
169+ # Is there a scalarmappable displayed?
170+ has_sm = bool (mappables )
167171
168172 datalist = [(general , "Axes" , "" )]
169173 if curves :
170174 datalist .append ((curves , "Curves" , "" ))
171- if images :
172- datalist .append ((images , "Images" , "" ))
175+ if mappables :
176+ datalist .append ((mappables , "Images, etc. " , "" ))
173177
174178 def apply_callback (data ):
175179 """This function will be called to apply changes"""
@@ -178,7 +182,7 @@ def apply_callback(data):
178182
179183 general = data .pop (0 )
180184 curves = data .pop (0 ) if has_curve else []
181- images = data .pop (0 ) if has_image else []
185+ mappables = data .pop (0 ) if has_sm else []
182186 if data :
183187 raise ValueError ("Unexpected field" )
184188
@@ -223,14 +227,17 @@ def apply_callback(data):
223227 line .set_markerfacecolor (markerfacecolor )
224228 line .set_markeredgecolor (markeredgecolor )
225229
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 , mappable_settings in enumerate (mappables ):
232+ mappable = mappabledict [mappablelabels [index ]]
233+ if len (mappable_settings ) == 5 :
234+ label , cmap , low , high , interpolation = mappable_settings
235+ mappable .set_interpolation (interpolation )
236+ elif len (mappable_settings ) == 4 :
237+ label , cmap , low , high = mappable_settings
238+ mappable .set_label (label )
239+ mappable .set_cmap (cm .get_cmap (cmap ))
240+ mappable .set_clim (* sorted ([low , high ]))
234241
235242 # re-generate legend, if checkbox is checked
236243 if generate_legend :
0 commit comments