1- import os
21import glob
32import json
3+ import os
4+
45import h5py
56import numpy as np
67
78from .. import options
8- from .braindata import BrainData , VolumeData , VertexData
9+ from .braindata import BrainData , VertexData , VolumeData
910
1011default_cmap = options .config .get ("basic" , "default_cmap" )
1112
13+ # register_cmap is deprecated in matplotlib > 3.7.0 and replaced by colormaps.register
14+ try :
15+ from matplotlib import colormaps as cm
16+ def register_cmap (cmap ):
17+ return cm .register (cmap )
18+ except ImportError :
19+ from matplotlib .cm import register_cmap
20+
1221
1322def normalize (data ):
1423 if isinstance (data , tuple ):
@@ -193,7 +202,8 @@ def _write_hdf(self, h5, name="data", data=None, xfmname=None):
193202 def get_cmapdict (self ):
194203 """Returns a dictionary with cmap information."""
195204
196- from matplotlib import colors , pyplot as plt
205+ from matplotlib import colors
206+ from matplotlib import pyplot as plt
197207
198208 try :
199209 # plt.get_cmap accepts:
@@ -206,18 +216,19 @@ def get_cmapdict(self):
206216 cmapdir = options .config .get ('webgl' , 'colormaps' )
207217 colormaps = glob .glob (os .path .join (cmapdir , "*.png" ))
208218 colormaps = dict (((os .path .split (c )[1 ][:- 4 ], c ) for c in colormaps ))
209- if not self .cmap in colormaps :
219+ if self .cmap not in colormaps :
210220 raise ValueError ('Unkown color map %s' % self .cmap )
211221 I = plt .imread (colormaps [self .cmap ])
212- cmap = colors .ListedColormap (np .squeeze (I ))
222+ name = self .cmap if isinstance (self .cmap , str ) else self .cmap .name
223+ cmap = colors .ListedColormap (np .squeeze (I ), name = name )
213224 # Register colormap to matplotlib to avoid loading it again
214- plt . register_cmap (self . cmap , cmap )
225+ register_cmap (cmap )
215226
216227 return dict (cmap = cmap , vmin = self .vmin , vmax = self .vmax )
217228
218229 @property
219230 def raw (self ):
220- from matplotlib import colors , cm
231+ from matplotlib import cm , colors
221232
222233 cmap = self .get_cmapdict ()['cmap' ]
223234 # Normalize colors according to vmin, vmax
@@ -398,5 +409,5 @@ def u(s, encoding='utf8'):
398409 return s
399410
400411
401- from .viewRGB import VolumeRGB , VertexRGB , Colors
402- from .view2D import Volume2D , Vertex2D
412+ from .viewRGB import Colors , VertexRGB , VolumeRGB
413+ from .view2D import Vertex2D , Volume2D
0 commit comments