当前位置: 首页>>代码示例>>Python>>正文


Python pyplot.register_cmap函数代码示例

本文整理汇总了Python中matplotlib.pyplot.register_cmap函数的典型用法代码示例。如果您正苦于以下问题:Python register_cmap函数的具体用法?Python register_cmap怎么用?Python register_cmap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了register_cmap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: myblues

 def myblues(self):
     cdict={'red': ((0.0,1.0,1.0),(1.0,0.0,0.0)),
            'green': ((0.0,1.0,1.0),(1.0,0.0,0.0)),
            'blue': ((0.0,1.0,1.0),(1.0,1.0,1.0))}
     myblues=LinearSegmentedColormap('MyBlues',cdict)
     plot.register_cmap(cmap=myblues)
     self.cmap='MyBlues'
开发者ID:zyh329,项目名称:o2scl,代码行数:7,代码来源:o2py.py

示例2: custom_cmap

def custom_cmap(_sample, _reverse=False):
    midpoint  = .5
    from scipy.ndimage import imread
    im = imread(_sample, mode='RGBA')
    im = im[10:-10,20:-20,:]
    im = im/im.max()
    if _reverse:
        im = np.rot90(im,2)
    nx,ny,nz = im.shape
    my_index = np.linspace(0,ny,257, endpoint=False)
    cdict = {
        'red': [],
        'green': [],
        'blue': [],
        'alpha': []
    }
    shift_index = np.hstack([
        np.linspace(0.0, midpoint, 128, endpoint=False),
        np.linspace(midpoint, 1.0, 129, endpoint=True)
    ])
    for i, si in zip(my_index, shift_index):
        i = int(i)
        r,g,b,a = (im[0,i,0],
                   im[0,i,1],
                   im[0,i,2],
                   im[0,i,3])
        cdict['red'].append((si, r, r))
        cdict['green'].append((si, g, g))
        cdict['blue'].append((si, b, b))
        cdict['alpha'].append((si, a, a))
    mycmap = matplotlib.colors.LinearSegmentedColormap('custom', cdict)
    plt.register_cmap(cmap=mycmap)
    return mycmap
开发者ID:fhorta,项目名称:palette2colormap,代码行数:33,代码来源:palette2colormap.py

示例3: shifted_cmap

def shifted_cmap(cmap,vmin,vmax,start=0.0,stop=1.0,name='new_cmap'):
	""" This code comes primarily from an answer to a question on stackoverflow
	url as of 2016-06-30 was http://stackoverflow.com/questions/7404116/defining-the-midpoint-of-a-colormap-in-matplotlib
	and the answer / code was from Paul H. http://stackoverflow.com/users/1552748/paul-h
	"""
	mid = 1.0-vmax/(vmax + np.absolute(vmin))
	colors = {
	'red': [],
	'green': [],
	'blue': [],
	'alpha': []
	}
	reg_index = np.linspace(start,stop,257)
	shift_index = np.hstack([
        np.linspace(0.0, mid, 128, endpoint=False), 
        np.linspace(mid, 1.0, 129, endpoint=True)
    ])

	for ri, si in zip(reg_index, shift_index):
	    r, g, b, a = cmap(ri)

	    colors['red'].append((si, r, r))
	    colors['green'].append((si, g, g))
	    colors['blue'].append((si, b, b))
	    colors['alpha'].append((si, a, a))

	newcmap = matplotlib.colors.LinearSegmentedColormap(name, colors)
	plt.register_cmap(cmap=newcmap)

	return newcmap
开发者ID:daviddewhurst,项目名称:symbolic,代码行数:30,代码来源:plotting.py

示例4: spec_colormap

def spec_colormap():
# Makes the colormap that we like for spectrograms

    cmap = np.zeros((64,3))
    cmap[0,2] = 1.0

    for ib in range(21):
        cmap[ib+1,0] = (31.0+ib*(12.0/20.0))/60.0
        cmap[ib+1,1] = (ib+1.0)/21.0
        cmap[ib+1,2] = 1.0

    for ig in range(21):
        cmap[ig+ib+1,0] = (21.0-(ig)*(12.0/20.0))/60.0
        cmap[ig+ib+1,1] = 1.0
        cmap[ig+ib+1,2] = 0.5+(ig)*(0.3/20.0)

    for ir in range(21):
        cmap[ir+ig+ib+1,0] = (8.0-(ir)*(7.0/20.0))/60.0
        cmap[ir+ig+ib+1,1] = 0.5 + (ir)*(0.5/20.0)
        cmap[ir+ig+ib+1,2] = 1

    for ic in range(64):
        (cmap[ic,0], cmap[ic,1], cmap[ic,2]) = colorsys.hsv_to_rgb(cmap[ic,0], cmap[ic,1], cmap[ic,2])
    
    spec_cmap = pltcolors.ListedColormap(cmap, name=u'SpectroColorMap', N=64)
    plt.register_cmap(cmap=spec_cmap)
开发者ID:choldgraf,项目名称:LaSP,代码行数:26,代码来源:sound.py

示例5: compare_spectra

def compare_spectra():
    import mywfc3.stgrism as st
    import unicorn
    
    ### Fancy colors
    import seaborn as sns
    import matplotlib.pyplot as plt
    cmap = sns.cubehelix_palette(as_cmap=True, light=0.95, start=0.5, hue=0.4, rot=-0.7, reverse=True)
    cmap.name = 'sns_rot'
    plt.register_cmap(cmap=cmap)
    sns.set_style("ticks", {"ytick.major.size":3, "xtick.major.size":3})
    plt.set_cmap('sns_rot')
    #plt.gray()
    
    fig = st.compare_methods(x0=787, y0=712, v=np.array([-1.5,4])*0.6, NX=180, NY=40, direct_off=100, final=True, mask_lim = 0.02)
    #fig.tight_layout()
    unicorn.plotting.savefig(fig, '/tmp/compare_model_star.pdf', dpi=300)

    fig = st.compare_methods(x0=485, y0=332, v=np.array([-1.5,4])*0.2, NX=180, NY=40, direct_off=100, final=True, mask_lim = 0.1)
    unicorn.plotting.savefig(fig, '/tmp/compare_model_galaxy.pdf', dpi=300)

    fig = st.compare_methods(x0=286, y0=408, v=np.array([-1.5,4])*0.08, NX=180, NY=40, direct_off=100, final=True, mask_lim = 0.1)
    unicorn.plotting.savefig(fig, '/tmp/compare_model_galaxy2.pdf', dpi=300)

    fig = st.compare_methods(x0=922, y0=564, v=np.array([-1.5,4])*0.2, NX=180, NY=40, direct_off=100, final=True, mask_lim = 0.15)
    unicorn.plotting.savefig(fig, '/tmp/compare_model_galaxy3.pdf', dpi=300)
开发者ID:gbrammer,项目名称:wfc3,代码行数:26,代码来源:stgrism.py

示例6: main

def main():
    plt.register_cmap(name='viridis', cmap=cmaps.viridis)
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    X = np.linspace(0.1, 20, num=50)
    Y = np.linspace(0.1, 20, num=50)
    Z = np.array([0.]*X.shape[0]*Y.shape[0])
    Z.shape = (X.shape[0], Y.shape[0])
    for i in range(X.shape[0]):
        for j in range(Y.shape[0]):
            he = hyperexp(0.5, X[i], Y[j])
            Z[i][j] = he.CoV()

    X, Y = np.meshgrid(X, Y)
    plt.xlabel('lambda1')
    plt.ylabel('lambda2')
    ax.set_zlabel('CoV')
    surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cmaps.viridis,
                           linewidth=0, antialiased=False, vmin=0., vmax=6)
    ax.set_zlim(0, 6)
    ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))

    fig.colorbar(surf, shrink=0.5, aspect=5)

    plt.show()
    return
开发者ID:pixki,项目名称:redesestocasticas,代码行数:26,代码来源:graph_cov.py

示例7: make_rainbow

def make_rainbow(a=0.75, b=0.2, name='custom_rainbow', register=False):
    """
    Use a=0.7, b=0.2 for a darker end.

    when 0.5<=a<=1.5, should have b >= (a-0.5)/2 or 0 <= b <= (a-1)/3
    when 0<=a<=0.5, should have b >= (0.5-a)/2 or 0<= b<= -a/3
    to assert the monoique

    To show the parameter dependencies interactively in notebook
    ```
    %matplotlib inline
    from ipywidgets import interact
    def func(a=0.75, b=0.2):
        cmap = gene_rainbow(a=a, b=b)
        show_cmap(cmap)
    interact(func, a=(0, 1, 0.05), b=(0.1, 0.5, 0.05))
    ```
    """
    def gfunc(a, b, c=1):
        def func(x):
            return c * np.exp(-0.5 * (x - a)**2 / b**2)
        return func

    cdict = {"red": gfunc(a, b),
             "green": gfunc(0.5, b),
             "blue": gfunc(1 - a, b)
             }
    cmap = mpl.colors.LinearSegmentedColormap(name, cdict)
    if register:
        plt.register_cmap(cmap=cmap)
        plt.rc('image', cmap=cmap.name)
    return cmap
开发者ID:syrte,项目名称:handy,代码行数:32,代码来源:cmap.py

示例8: register_colour_maps

def register_colour_maps():
    cdict = {'red':   ((0.0,  0.0, 0.0),
                       (0.0,  0.0, 0.0),
                       (1.0,  1.0, 1.0)),
                       
         'green': ((0.0,  0.0, 0.0),
                   (0.0,  0.0, 0.0),
                   (1.0,  1.0, 1.0)),
                   
         'blue':  ((0.0,  0.0, 0.0),
                   (0.0,  0.0, 0.0),
                   (1.0,  1.0, 1.0))}
    
    plt.register_cmap(name='GreyIntensity', data=cdict)
    
    cdict2 = {'red': ((0.0, 0.0, 0.0),
                 (0.5, 1.0, 0.7),
                 (1.0, 1.0, 1.0)),
         'green': ((0.0, 0.0, 0.0),
                   (0.5, 1.0, 0.0),
                   (1.0, 1.0, 1.0)),
         'blue': ((0.0, 0.0, 0.0),
                  (0.5, 1.0, 0.0),
                  (1.0, 0.5, 1.0))}
    
    plt.register_cmap(name='RedSplit', data=cdict2)
开发者ID:danmaclean,项目名称:raspberry_pi,代码行数:26,代码来源:IRCamera.py

示例9: _set_colors

def _set_colors():
    HighRGB = np.array([26, 152, 80]) / 255.
    MediumRGB = np.array([255, 255, 191]) / 255.
    LowRGB = np.array([0, 0, 0]) / 255.
    cdict = _set_cdict(HighRGB, MediumRGB, LowRGB)
    plt.register_cmap(name='PyMKS', data=cdict)
    plt.set_cmap('PyMKS')
开发者ID:faical-yannick-congo,项目名称:pymks,代码行数:7,代码来源:tools.py

示例10: remappedColorMap

def remappedColorMap(cmap, data=False, start=0, midpoint=0.5, stop=1.0, name='shiftedcmap'):
	'''
	Function to offset the median value of a colormap, and scale the
	remaining color range. Useful for data with a negative minimum and
	positive maximum where you want the middle of the colormap's dynamic
	range to be at zero.

	Input
	-----
	cmap : The matplotlib colormap to be altered
	data: You can provide your data as a numpy array, and the following
		operations will be computed automatically for you.
	start : Offset from lowest point in the colormap's range.
		Defaults to 0.0 (no lower ofset). Should be between
		0.0 and 0.5; if your dataset vmax <= abs(vmin) you should leave 
		this at 0.0, otherwise to (vmax-abs(vmin))/(2*vmax) 
	midpoint : The new center of the colormap. Defaults to 
		0.5 (no shift). Should be between 0.0 and 1.0; usually the
		optimal value is abs(vmin)/(vmax+abs(vmin)) 
	stop : Offset from highets point in the colormap's range.
		Defaults to 1.0 (no upper ofset). Should be between
		0.5 and 1.0; if your dataset vmax >= abs(vmin) you should leave 
		this at 1.0, otherwise to (abs(vmin)-vmax)/(2*abs(vmin)) 
	'''
    
	if isinstance(data, np.ndarray):
		start, midpoint, stop = auto_remap(data)
    
    	cdict = {
    		'red': [],
    		'green': [],
    		'blue': [],
    		'alpha': []
    	}

    	# regular index to compute the colors
    	reg_index = np.hstack([
    			np.linspace(start, 0.5, 128, endpoint=False), 
    			np.linspace(0.5, stop, 129)
    	])

    	# shifted index to match the data
    	shift_index = np.hstack([
    			np.linspace(0.0, midpoint, 128, endpoint=False), 
    			np.linspace(midpoint, 1.0, 129)
    	])

    	for ri, si in zip(reg_index, shift_index):
    		r, g, b, a = cmap(ri)

        	cdict['red'].append((si, r, r))
        	cdict['green'].append((si, g, g))
        	cdict['blue'].append((si, b, b))
        	cdict['alpha'].append((si, a, a))

    	newcmap = matplotlib.colors.LinearSegmentedColormap(name, cdict)
    	plt.register_cmap(cmap=newcmap)

	return newcmap
开发者ID:TheChymera,项目名称:chr-helpers,代码行数:59,代码来源:chr_matplotlib.py

示例11: shift_cmap

def shift_cmap(cmap, start=0, midpoint=0.5, stop=1, name='shiftedcmap'):
    '''Offset the median value of a colormap.
    
    And scale the remaining color range. Useful for data with a negative
    minimum and positive maximum where you want the middle of the colormap's
    dynamic range to be at zero.

    Input
    -----
      cmap : The matplotlib colormap to be altered
      start : Offset from lowest point in the colormap's range.
          Defaults to 0.0 (no lower ofset). Should be between
          0.0 and 0.5; if your dataset mean is negative you should leave 
          this at 0.0, otherwise to (vmax-abs(vmin))/(2*vmax) 
      midpoint : The new center of the colormap. Defaults to 
          0.5 (no shift). Should be between 0.0 and 1.0; usually the
          optimal value is abs(vmin)/(vmax+abs(vmin)) 
      stop : Offset from highets point in the colormap's range.
          Defaults to 1.0 (no upper ofset). Should be between
          0.5 and 1.0; if your dataset mean is positive you should leave 
          this at 1.0, otherwise to (abs(vmin)-vmax)/(2*abs(vmin)) 

    Credits
    -------
    Paul H (initial version)
    Horea Christian (additions/modifications)
    Fernando Paolo (additions/modifications)

    TODO
    ----
    Set 'start' and 'stop' dynamically when negative/positive bounds.

    '''
    # if array given, find optimal value to center new cmap
    if np.ndim(midpoint) != 0:
        midpoint = np.asarray(midpoint)[~np.isnan(midpoint)]
        midpoint = abs(midpoint.min()) / float(abs(midpoint.max()) + \
                                               abs(midpoint.min())) 
    # regular index to compute the colors
    reg_index = np.hstack([
        np.linspace(start, 0.5, 128, endpoint=False), 
        np.linspace(0.5, stop, 129, endpoint=True)
    ])
    # shifted index to match the midpoint of the data
    new_index = np.hstack([
        np.linspace(0.0, midpoint, 128, endpoint=False), 
        np.linspace(midpoint, 1.0, 129, endpoint=True)
    ])
    cdict = {'red': [], 'green': [], 'blue': [], 'alpha': []}
    for ri, si in zip(reg_index, new_index):
        r, g, b, a = cmap(ri)
        cdict['red'].append((si, r, r))
        cdict['green'].append((si, g, g))
        cdict['blue'].append((si, b, b))
        cdict['alpha'].append((si, a, a))
    newcmap = mpl.colors.LinearSegmentedColormap(name, cdict, 256)
    plt.register_cmap(cmap=newcmap)
    return newcmap
开发者ID:mohseniaref,项目名称:altimpy,代码行数:58,代码来源:viz.py

示例12: make_subplot

def make_subplot(options, ax, dplot, slicearg, data, pars, xvar, yvar, xidx, yidx, a, b):
    sc = a / (a+b) / 0.5
    sc2 = b / (a+b) / 0.5

    anm = {
        'red': [
            (0., 0.0, 0.0),
            (sc*0.5, 1.0, 1.0),
            (sc*0.5 + (0.817460-0.5)*sc2, 1.0, 1.0),
            (1.0, 0.8, 0.8)],

        'green': [
            (0., 0.0, 0.0),
            (sc*0.4, 1.0, 1.0),
            (sc*0.5, 1.0, 1.0),
            (sc*0.5 + (0.626984-0.5)*sc2, 1.0, 1.0),
            (sc*0.5 + (0.817460-0.5)*sc2, 0.6, 0.6),
            (1.0, 0.0, 0.0)],

        'blue': [
            (0.0, 0.4, 0.4),
            (sc*0.25, 1.0, 1.0),
            (sc*0.5, 1.0, 1.0),
            (sc*0.5 + (0.626984-0.5)*sc2, 0., 0.),
            (1.0, 0.0, 0.0)]
        }

    if sc == 0.0:
        for k in anm.iterkeys():
            anm[k] = anm[k][1:]
    # Fix color scale if only positive values are present.
    elif a < 0.001:
        for k in anm.iterkeys():
            anm[k][0] = (0., 1.0, 1.0)

    if b < 0.001:
        anm['red'] = anm['red'][0:1] + [(1, 1, 1)]
        anm['green'] = anm['green'][0:2] + [(1, 1, 1)]
        anm['blue'] = anm['blue'][0:2] + [(1, 1 ,1)]

    anm_cmap = LinearSegmentedColormap('ANM', anm)
    plt.register_cmap(cmap=anm_cmap)

    aspect = ((data[pars[xidx]][-1] - data[pars[xidx]][0]) /
              (data[pars[yidx]][-1] - data[pars[yidx]][0])) / options.panel_aspect

    im = ax.imshow(dplot[slicearg],
           extent=(data[pars[xidx]][0], data[pars[xidx]][-1],
                   data[pars[yidx]][0], data[pars[yidx]][-1]),
           aspect=aspect,
           interpolation='bilinear',
#           interpolation='nearest',
           vmin = -a,
           vmax = b,
           cmap = anm_cmap,
           origin='lower')

    return im
开发者ID:mjanusz,项目名称:sdepy,代码行数:58,代码来源:anm_plot.py

示例13: lin_cmap_gen

def lin_cmap_gen(incolgs, regname, fractions = None):
    '''
    Generates a color map with the given color list (incolgs).
    Accepts a list of color words (defined by the color.gs script:
        http://kodama.fubuki.info/wiki/wiki.cgi/GrADS/script/color.gs?lang=en)
    or a list of (r,g,b) values. The r,g,b values can be either 0<=x<=1 or 0<=x<=255

    input:
        incolgs: Input color map request
        regname: Name for matplotlib to register color map.
        fractions: Fraction for each color to take up- these values must
                   add to 1. If not, a ValueException is raised. (NOT YET IMPLEMENTED)

    returns:
        a LinearSegmentedColormap containing your colors.
    '''
    collists = incolgs
    reds = list()
    greens = list()
    blues = list()
    reds_prep = list()
    greens_prep = list()
    blues_prep = list()

    if fractions != None:
        raise NotImplementedError("Fractional colors are not yet implemented.")

    for i, color in enumerate(collists):
        try:
            if (color[0] >= 0 and color[0] <= 255 and
                color[1] >= 0 and color[1] <= 255 and
                color[2] >= 0 and color[2] <= 255):

                rgb = convert_color(color)
            else:
                raise ValueError("Colors need to be between 0 and 255")

        except TypeError:
            rgb = get_rgb(color)

        reds.append(rgb[0])
        greens.append(rgb[1])
        blues.append(rgb[2])
    for i in range(len(reds)):
        rp = ((float(i)/(len(reds)-1)))
        drp = ((1.0/(len(reds)-1)))
        if rp+drp >=1:
            drp = 0
        reds_prep.append((rp, reds[i],reds[i]))
        blues_prep.append((rp, blues[i], blues[i]))
        greens_prep.append((rp, greens[i], greens[i]))

    cdict = {'red': tuple(reds_prep), 'blue': tuple(blues_prep), 
             'green': tuple(greens_prep)}
    #print(cdict)
    ucmap = LinearSegmentedColormap(regname, cdict)
    plt.register_cmap(cmap=ucmap)
    return ucmap
开发者ID:freemansw1,项目名称:gen_cmap,代码行数:58,代码来源:gen_cmap.py

示例14: shift_colormap

def shift_colormap(cmap, start=0, midpoint=0.5, stop=1.0, name='shiftedcmap'):
    '''
    Function to offset the "center" of a colormap. Useful for
    data with a negative min and positive max and you want the
    middle of the colormap's dynamic range to be at zero

    Parameters
    ----------
    cmap : The matplotlib colormap to be altered
    start : Offset from lowest point in the colormap's range.
      Defaults to 0.0 (no lower ofset). Should be between
      0.0 and `midpoint`.
    midpoint : The new center of the colormap. Defaults to
      0.5 (no shift). Should be between 0.0 and 1.0. In
      general, this should be  1 - vmax/(vmax + abs(vmin))
      For example if your data range from -15.0 to +5.0 and
      you want the center of the colormap at 0.0, `midpoint`
      should be set to  1 - 5/(5 + 15)) or 0.75
    stop : Offset from highets point in the colormap's range.
      Defaults to 1.0 (no upper ofset). Should be between
      `midpoint` and 1.0.
    
    Returns
    -------
    new_cmap : A new colormap that has been shifted. 
    '''
    
    import matplotlib as mpl
    import matplotlib.pyplot as plt

    cdict = {
        'red': [],
        'green': [],
        'blue': [],
        'alpha': []
    }

    # regular index to compute the colors
    reg_index = np.linspace(start, stop, 257)

    # shifted index to match the data
    shift_index = np.hstack([
        np.linspace(0.0, midpoint, 128, endpoint=False), 
        np.linspace(midpoint, 1.0, 129, endpoint=True)
    ])

    for ri, si in zip(reg_index, shift_index):
        r, g, b, a = cmap(ri)

        cdict['red'].append((si, r, r))
        cdict['green'].append((si, g, g))
        cdict['blue'].append((si, b, b))
        cdict['alpha'].append((si, a, a))

    new_cmap = mpl.colors.LinearSegmentedColormap(name, cdict)
    plt.register_cmap(cmap=new_cmap)

    return new_cmap
开发者ID:jGaboardi,项目名称:pysal,代码行数:58,代码来源:utils.py

示例15: _set_colors

def _set_colors():
    """
    Helper function used to set the color map.
    """
    HighRGB = np.array([26, 152, 80]) / 255.
    MediumRGB = np.array([255, 255, 191]) / 255.
    LowRGB = np.array([0, 0, 0]) / 255.
    cdict = _set_cdict(HighRGB, MediumRGB, LowRGB)
    plt.register_cmap(name='PyMKS', data=cdict)
    plt.set_cmap('PyMKS')
开发者ID:bodagetta,项目名称:pymks,代码行数:10,代码来源:tools.py


注:本文中的matplotlib.pyplot.register_cmap函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。