| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4dbbd22 commit 812d826
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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() | ||
| 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: | ||
| 145 | 145 | 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 = [] | ||
| 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 mappablelabels: | ||
| 151 | + mappable = mappabledict[label] | ||
| 152 | + cmap = mappable.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 = mappable.get_clim() | ||
| 156 | + mappabledata = [ | ||
| 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(mappable, "get_interpolation"): # Images. | ||
| 163 | + mappabledata.append(( | ||
| 164 | + 'Interpolation', | ||
| 165 | + [mappable.get_interpolation(), | ||
| 166 | + *((name, name) | ||
| 167 | + for name in sorted(mimage.interpolations_names))])) | ||
| 168 | + mappables.append([mappabledata, label, ""]) | ||
| 169 | + # Is there a scalarmappable displayed? | ||
| 170 | + has_sm = bool(mappables) | ||
| 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 mappables: | ||
| 176 | + datalist.append((mappables, "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 | + mappables = data.pop(0) if has_sm else [] | ||
| 182 | 186 | if data: | |
| 183 | 187 | raise ValueError("Unexpected field") | |
| 184 | 188 | ||
@@ -223,14 +227,17 @@ 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, 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])) | ||
| 234 | 241 | ||
| 235 | 242 | # re-generate legend, if checkbox is checked | |
| 236 | 243 | if generate_legend: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -250,6 +250,7 @@ def test_figureoptions(): | |||
| 250 | 250 | fig, ax = plt.subplots() | |
| 251 | 251 | ax.plot([1, 2]) | |
| 252 | 252 | ax.imshow([[1]]) | |
| 253 | + ax.scatter(range(3), range(3), c=range(3)) | ||
| 253 | 254 | with mock.patch( | |
| 254 | 255 | "matplotlib.backends.qt_editor.formlayout.FormDialog.exec_", | |
| 255 | 256 | lambda self: None): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments