我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用matplotlib.cm.register_cmap()。
def add_cmap(name, cdict): """ Adds a colormap to the colormaps available in yt for this session """ yt_colormaps[name] = \ cc.LinearSegmentedColormap(name,cdict,256) mcm.datad[name] = cdict mcm.__dict__[name] = cdict try: # API compatibility mcm.register_cmap(name, yt_colormaps[name]) except AttributeError: pass # The format is as follows: # First number is the number at which we are defining a color breakpoint # Second number is the (0..1) number to interpolate to when coming *from below* # Third number is the (0..1) number to interpolate to when coming *from above* # Next up is boilerplate -- the name, the colormap dict we just made, and the # number of segments we want. This is probably fine as is.
def discrete_cmap(N=8): # define individual colors as hex values cpool = [ '#000000', '#00EE00', '#0000EE', '#00EEEE', '#EE0000', '#FFFF00', '#EE00EE', '#FFFFFF'] cmap_i8 = col.ListedColormap(cpool[0:N], 'i8') cm.register_cmap(cmap=cmap_i8) # ----------------------------------------------------------------- # build a list of residual images
def discrete_cmap(N=8): # define individual colors as hex values cpool = [ '#000000', '#00EE00', '#0000EE', '#00EEEE', '#EE0000','#FFFF00', '#EE00EE', '#FFFFFF'] cmap_i8 = colors.ListedColormap(cpool[0:N], 'i8') cm.register_cmap(cmap=cmap_i8) return cmap_i8
def register_cmap(name,cmap): pass
def mpl_cm(name,colorlist): cm[name] = LinearSegmentedColormap.from_list(name, colorlist, N=len(colorlist)) register_cmap("cet_"+name, cmap=cm[name]) return cm[name]
def getColorMap(): """ This function returns the standard University of Tuebingen Colormap. """ midBlue = np.array([165, 30, 55])/255 lightBlue = np.array([210, 150, 0])/255 steps = 200 MAP = _mcolors.LinearSegmentedColormap.from_list('Tuebingen', \ [midBlue, lightBlue, [1,1,1]],N = steps, gamma = 1.0) _cm.register_cmap(name = 'Tuebingen', cmap = MAP) return MAP