Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2b53758

Browse filesBrowse files
committed
Don't fail on equal-but-differently-named cmaps in qt figureoptions.
Currently, opening the Qt figureoptions UI for an image whose cmap is not registered in the colormap registry, has a name not matching any registry entry, but is actually equal (`==`, i.e. has the same LUT and colorbar-extension attributes) to a registry entry, leads to an error. A typical example would be ``` import cmap, pylab as p # third-party p.imshow([[0, 1]], cmap=cmap.Colormap("bids:magma").to_mpl()) ``` and opening the qt figure options; this leads to the error "index 'bids:magma' is invalid ...". Note that if the cmap is different from any registered cmap then we already add it to the UI combobox (try e.g. `cmap=cmap.Colormap("imagej:fire")`); the only problem was if it was equal to a registered cmap (this arises because when the code was originally written, cmap instance equality was by identity, not by comparing LUTs, so the `cmap not in cm._colormaps.values()` check behaved differently). Fix that by checking whether the colormap *name* is registered. The behavior is still ill-defined in the opposite (theoretical) case of an unregistered cmap different from any registered cmap but with a matching name, but I'd argue that case is more pathological. Test by running the above code and opening the qt figureoptions.
1 parent 183b04f commit 2b53758
Copy full SHA for 2b53758

File tree

Expand file treeCollapse file tree

1 file changed

+1
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+1
-1
lines changed

‎lib/matplotlib/backends/qt_editor/figureoptions.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/qt_editor/figureoptions.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def prepare_data(d, init):
149149
cmaps = [(cmap, name) for name, cmap in sorted(cm._colormaps.items())]
150150
for label, mappable in labeled_mappables:
151151
cmap = mappable.get_cmap()
152-
if cmap not in cm._colormaps.values():
152+
if cmap.name not in cm._colormaps:
153153
cmaps = [(cmap, cmap.name), *cmaps]
154154
low, high = mappable.get_clim()
155155
mappabledata = [

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.