Skip to content

Commit

Permalink
FIX cmap name
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdoc committed May 16, 2024
1 parent 206c197 commit 2d1ea76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions cortex/dataset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from matplotlib.cm import register_cmap
except ImportError:
from matplotlib import colormaps
def register_cmap(*args, **kwargs):
return colormaps.register(*args, **kwargs)
def register_cmap(cmap):
return colormaps.register(cmap)


def normalize(data):
Expand Down Expand Up @@ -219,8 +219,9 @@ def get_cmapdict(self):
raise ValueError('Unkown color map %s' % self.cmap)
I = plt.imread(colormaps[self.cmap])
cmap = colors.ListedColormap(np.squeeze(I))
cmap.name = self.cmap
# Register colormap to matplotlib to avoid loading it again
register_cmap(self.cmap, cmap)
register_cmap(cmap)

return dict(cmap=cmap, vmin=self.vmin, vmax=self.vmax)

Expand Down
7 changes: 4 additions & 3 deletions cortex/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from matplotlib.cm import register_cmap
except ImportError:
from matplotlib import colormaps
def register_cmap(*args, **kwargs):
return colormaps.register(*args, **kwargs)
def register_cmap(cmap):
return colormaps.register(cmap)


class DocLoader(object):
Expand Down Expand Up @@ -1008,8 +1008,9 @@ def get_cmap(name):
if name in colormaps:
I = plt.imread(colormaps[name])
cmap = colors.ListedColormap(np.squeeze(I))
cmap.name = name
try:
register_cmap(name, cmap)
register_cmap(cmap)
except:
print(f"Color map {name} is already registered.")
else:
Expand Down

0 comments on commit 2d1ea76

Please sign in to comment.