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


Python colors.ListedColormap方法代码示例

本文整理汇总了Python中matplotlib.colors.ListedColormap方法的典型用法代码示例。如果您正苦于以下问题:Python colors.ListedColormap方法的具体用法?Python colors.ListedColormap怎么用?Python colors.ListedColormap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.colors的用法示例。


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

示例1: check_segmentation

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def check_segmentation(fn_subject):
    from scipy import ndimage
    import matplotlib.pylab as pl
    from matplotlib.colors import ListedColormap
    files = simnibs.SubjectFiles(fn_subject + '.msh')
    T1 = nib.load(files.T1)
    masks = nib.load(files.final_contr).get_data()
    lines = np.linalg.norm(np.gradient(masks), axis=0) > 0
    print(lines.shape)
    viewer = NiftiViewer(T1.get_data(), T1.affine)
    cmap = pl.cm.jet
    my_cmap = cmap(np.arange(cmap.N))
    my_cmap[:,-1] = np.linspace(0, 1, cmap.N)
    my_cmap = ListedColormap(my_cmap)
    viewer.add_overlay(lines, cmap=my_cmap)
    viewer.show() 
开发者ID:simnibs,项目名称:simnibs,代码行数:18,代码来源:nifti_viewer.py

示例2: ehtcmap

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def ehtcmap(N=Nq,
            Jpmin=15.0, Jpmax=95.0,
            Cpmin= 0.0, Cpmax=64.0,
            hpmin=None, hpmax=90.0,
            hp=None,
            **kwargs):
    name = kwargs.pop('name', "new eht colormap")

    Jp = np.linspace(Jpmin, Jpmax, num=N)
    if hp is None:
        if hpmin is None:
            hpmin = hpmax - 60.0
        q  = 0.25 * (hpmax - hpmin)
        hp = np.clip(np.linspace(hpmin-3*q, hpmax+q, num=N), hpmin, hpmax)
    elif callable(hp):
        hp = hp(np.linspace(0.0, 1.0, num=N))
    hp *= np.pi/180.0
    Cp = max_chroma(Jp, hp, Cpmin=Cpmin, Cpmax=Cpmax)

    Jpapbp = np.stack([Jp, Cp * np.cos(hp), Cp * np.sin(hp)], axis=-1)
    Jpapbp = symmetrize(Jpapbp, **kwargs)
    sRGB   = transform(Jpapbp, inverse=True)
    return ListedColormap(np.clip(sRGB, 0, 1), name=name) 
开发者ID:liamedeiros,项目名称:ehtplot,代码行数:25,代码来源:cmap.py

示例3: vis

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def vis(embed, vis_alg='PCA', pool_alg='REDUCE_MEAN'):
    plt.close()
    fig = plt.figure()
    plt.rcParams['figure.figsize'] = [21, 7]
    for idx, ebd in enumerate(embed):
        ax = plt.subplot(2, 6, idx + 1)
        vis_x = ebd[:, 0]
        vis_y = ebd[:, 1]
        plt.scatter(vis_x, vis_y, c=subset_label, cmap=ListedColormap(["blue", "green", "yellow", "red"]), marker='.',
                    alpha=0.7, s=2)
        ax.set_title('pool_layer=-%d' % (idx + 1))
    plt.tight_layout()
    plt.subplots_adjust(bottom=0.1, right=0.95, top=0.9)
    cax = plt.axes([0.96, 0.1, 0.01, 0.3])
    cbar = plt.colorbar(cax=cax, ticks=range(num_label))
    cbar.ax.get_yaxis().set_ticks([])
    for j, lab in enumerate(['ent.', 'bus.', 'sci.', 'heal.']):
        cbar.ax.text(.5, (2 * j + 1) / 8.0, lab, ha='center', va='center', rotation=270)
    fig.suptitle('%s visualization of BERT layers using "bert-as-service" (-pool_strategy=%s)' % (vis_alg, pool_alg),
                 fontsize=14)
    plt.show() 
开发者ID:hanxiao,项目名称:bert-as-service,代码行数:23,代码来源:example7.py

示例4: test_resample

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def test_resample():
    """
    Github issue #6025 pointed to incorrect ListedColormap._resample;
    here we test the method for LinearSegmentedColormap as well.
    """
    n = 101
    colorlist = np.empty((n, 4), float)
    colorlist[:, 0] = np.linspace(0, 1, n)
    colorlist[:, 1] = 0.2
    colorlist[:, 2] = np.linspace(1, 0, n)
    colorlist[:, 3] = 0.7
    lsc = mcolors.LinearSegmentedColormap.from_list('lsc', colorlist)
    lc = mcolors.ListedColormap(colorlist)
    lsc3 = lsc._resample(3)
    lc3 = lc._resample(3)
    expected = np.array([[0.0, 0.2, 1.0, 0.7],
                         [0.5, 0.2, 0.5, 0.7],
                         [1.0, 0.2, 0.0, 0.7]], float)
    assert_array_almost_equal(lsc3([0, 0.5, 1]), expected)
    assert_array_almost_equal(lc3([0, 0.5, 1]), expected) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:22,代码来源:test_colors.py

示例5: plot_colormap

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def plot_colormap(cmap, continuous=True, discrete=True, ndisc=9):
    """Make a figure displaying the color map in continuous and/or discrete form
    """
    nplots = int(continuous) + int(discrete)
    fig, axx = plt.subplots(figsize=(6,.5*nplots), nrows=nplots, frameon=False)
    axx = np.asarray(axx)
    i=0
    if continuous:
        norm = mcolors.Normalize(vmin=0, vmax=1)
        ColorbarBase(axx.flat[i], cmap=cmap, norm=norm, orientation='horizontal') ; i+=1
    if discrete:
        colors = cmap(np.linspace(0, 1, ndisc))
        cmap_d = mcolors.ListedColormap(colors, name=cmap.name)
        norm = mcolors.BoundaryNorm(np.linspace(0, 1, ndisc+1), len(colors))
        ColorbarBase(axx.flat[i], cmap=cmap_d, norm=norm, orientation='horizontal')
    for ax in axx.flat:
        ax.set_axis_off()
    fig.text(0.95, 0.5, cmap.name, va='center', ha='left', fontsize=12) 
开发者ID:j08lue,项目名称:pycpt,代码行数:20,代码来源:display.py

示例6: cmap_from_geo_uoregon

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def cmap_from_geo_uoregon(cname,
        baseurl='http://geog.uoregon.edu/datagraphics/color/',
        download=False):
    """Parse an online file from geography.uoregon.edu to create a Python colormap"""
    ext = '.txt'

    url = urljoin(baseurl, cname+ext)
    print(url)
    
    # process file directly from online source
    req = Request(url)
    response = urlopen(req)
    rgb = np.loadtxt(response, skiprows=2)
    
    # save original file
    if download:
        fname = os.path.basename(url) + ext
        urlretrieve (url, fname)
        
    return mcolors.ListedColormap(rgb, cname) 
开发者ID:j08lue,项目名称:pycpt,代码行数:22,代码来源:load.py

示例7: plot

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def plot(X,Y,pred_func):
    # determine canvas borders
    mins = np.amin(X,0); 
    mins = mins - 0.1*np.abs(mins);
    maxs = np.amax(X,0); 
    maxs = maxs + 0.1*maxs;

    ## generate dense grid
    xs,ys = np.meshgrid(np.linspace(mins[0,0],maxs[0,0],300), 
            np.linspace(mins[0,1], maxs[0,1], 300));


    # evaluate model on the dense grid
    Z = pred_func(np.c_[xs.flatten(), ys.flatten()]);
    Z = Z.reshape(xs.shape)

    # Plot the contour and training examples
    plt.contourf(xs, ys, Z, cmap=plt.cm.Spectral)
    plt.scatter(X[:, 0], X[:, 1], c=Y[:,1], s=50,
            cmap=colors.ListedColormap(['orange', 'blue']))
    plt.show() 
开发者ID:jasonbaldridge,项目名称:try-tf,代码行数:23,代码来源:plot_boundary_on_data.py

示例8: _override_sns_row_colors

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def _override_sns_row_colors(graph, row_colors):

    if not isinstance(row_colors, list):
        row_colors = row_colors.tolist()
    if isinstance(row_colors[0], tuple):
        # row_colors are in rgb(a) form
        unq_colors, color_class = np.unique(row_colors, axis=0, return_inverse=True)
        unq_colors = map(lambda x: tuple(x), unq_colors)
    else:
        unq_colors, color_class = np.unique(row_colors, return_inverse=True)
        unq_colors = unq_colors.tolist()

    rcax = graph.ax_row_colors
    rcax.clear()
    cmap = colors.ListedColormap(unq_colors)
    rcax.imshow(np.matrix(color_class).T, aspect='auto', cmap=cmap)
    rcax.get_xaxis().set_visible(False)
    rcax.get_yaxis().set_visible(False)

    return 
开发者ID:ratschlab,项目名称:pancanatlas_code_public,代码行数:22,代码来源:sf_heatmap.py

示例9: _sns_to_plotly

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def _sns_to_plotly(cmap: ListedColormap, pl_entries: int = 255
                   ) -> List[List[Union[float, str]]]:
    """Convert a color map to a plotly color scale.

    Args:
        cmap: Color map to be converted.
        pl_entries: Number of entries in the color scale.

    Returns:
        Color scale.
    """
    hgt = 1.0/(pl_entries-1)
    pl_colorscale = []

    for k in range(pl_entries):
        clr = list(map(np.uint8, np.array(cmap(k*hgt)[:3])*255))
        pl_colorscale.append([k*hgt, 'rgb'+str((clr[0], clr[1], clr[2]))])

    return pl_colorscale 
开发者ID:Qiskit,项目名称:qiskit-ibmq-provider,代码行数:21,代码来源:colormaps.py

示例10: plot_slic

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def plot_slic(array, clusters, K, S, output_figure = ''):
    fig = plt.figure(figsize=(8, 6))
    # create colormap based on cluster RGB centers
    slic_colormap = []
    for c in clusters:
        slic_colormap.append((c[0], c[1], c[2], 1.0))
    slic_listed_colormap = ListedColormap(slic_colormap)
    slic_norm = BoundaryNorm(range(K), K)
    plt.imshow(array, norm=slic_norm, cmap=slic_listed_colormap)
    # adjust image
    (rows, columns) = array.shape
    plt.xlim([0 - S, columns + S])
    plt.ylim([0 - S, rows + S])

    if output_figure != '':
        plt.savefig(output_figure, format='png', dpi=1000)
    else:
        plt.show()

# open dataset 
开发者ID:tkorting,项目名称:youtube,代码行数:22,代码来源:main.py

示例11: RDMcolormap

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def RDMcolormap(nCols=256):

    # blue-cyan-gray-red-yellow with increasing V (BCGRYincV)
    anchorCols = np.array([
        [0, 0, 1],
        [0, 1, 1],
        [.5, .5, .5],
        [1, 0, 0],
        [1, 1, 0],
    ])

    # skimage rgb2hsv is intended for 3d images (RGB)
    # here we add a new axis to our 2d anchorCols to satisfy skimage, and then squeeze
    anchorCols_hsv = rgb2hsv(anchorCols[np.newaxis, :]).squeeze()

    incVweight = 1
    anchorCols_hsv[:, 2] = (1-incVweight)*anchorCols_hsv[:, 2] + \
        incVweight*np.linspace(0.5, 1, anchorCols.shape[0]).T

    # anchorCols = brightness(anchorCols)
    anchorCols = hsv2rgb(anchorCols_hsv[np.newaxis, :]).squeeze()

    cols = colorScale(nCols, anchorCols)

    return ListedColormap(cols) 
开发者ID:Charestlab,项目名称:pyrsa,代码行数:27,代码来源:RDMcolormap.py

示例12: show

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def show(self, image, label_1s, label_2s, label_3s, label, label_at):
        import matplotlib.pyplot as plt
        from matplotlib import colors
        # make a color map of fixed colors
        cmap = colors.ListedColormap([(0,0,0), (0.5,0,0), (0,0.5,0), (0.5,0.5,0), (0,0,0.5), (0.5,0,0.5), (0,0.5,0.5)])
        bounds=[0,1,2,3,4,5,6,7]
        norm = colors.BoundaryNorm(bounds, cmap.N)

        fig, axes = plt.subplots(2,3)
        (ax1, ax2, ax3), (ax4, ax5, ax6) = axes
        ax1.set_title('image'); ax1.imshow(image)
        ax3.set_title('label'); ax2.imshow(label, cmap=cmap, norm=norm)
        ax3.set_title('label 1s'); ax3.imshow(label_1s, cmap=cmap, norm=norm)
        ax4.set_title('label 2s'); ax4.imshow(label_2s, cmap=cmap, norm=norm)
        ax5.set_title('label 3s'); ax5.imshow(label_3s, cmap=cmap, norm=norm)
        ax6.set_title('label at'); ax6.imshow(label_at, cmap=cmap, norm=norm)
        plt.show() 
开发者ID:speedinghzl,项目名称:Scale-Adaptive-Network,代码行数:19,代码来源:instance_attention.py

示例13: _color_palette

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def _color_palette(cmap, n_colors):
    import matplotlib.pyplot as plt
    from matplotlib.colors import ListedColormap
    import numpy as np

    colors_i = np.linspace(0, 1., n_colors)
    if isinstance(cmap, (list, tuple)):
        # we have a list of colors
        cmap = ListedColormap(cmap, N=n_colors)
        pal = cmap(colors_i)
    elif isinstance(cmap, str):
        # we have some sort of named palette
        try:
            # is this a matplotlib cmap?
            ensure_cmaps_loaded()
            cmap = plt.get_cmap(cmap)
        except ValueError:
            # or maybe we just got a single color as a string
            cmap = ListedColormap([cmap], N=n_colors)
        pal = cmap(colors_i)
    else:
        # cmap better be a LinearSegmentedColormap (e.g. viridis)
        pal = cmap(colors_i)

    return pal 
开发者ID:CCI-Tools,项目名称:cate,代码行数:27,代码来源:plot_helpers.py

示例14: cmap2rgba

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def cmap2rgba(cmap=None, N=None, interpolate=True):
    """Convert a colormap into a list of RGBA values.

    Parameters:
        cmap (str): Name of a registered colormap.
        N (int): Number of RGBA-values to return.
            If ``None`` use the number of colors defined in the colormap.
        interpolate (bool): Toggle the interpolation of values in the
            colormap.  If ``False``, only values from the colormap are
            used. This may lead to the re-use of a color, if the colormap
            provides less colors than requested. If ``True``, a lookup table
            is used to interpolate colors (default is ``True``).

    Returns:
        ndarray: RGBA-values.

    Examples:
        >>> cmap2rgba('viridis', 5)
        array([[ 0.267004,  0.004874,  0.329415,  1.      ],
            [ 0.229739,  0.322361,  0.545706,  1.      ],
            [ 0.127568,  0.566949,  0.550556,  1.      ],
            [ 0.369214,  0.788888,  0.382914,  1.      ],
            [ 0.993248,  0.906157,  0.143936,  1.      ]])
    """
    cmap = plt.get_cmap(cmap)

    if N is None:
        N = cmap.N

    nlut = N if interpolate else None

    if interpolate and isinstance(cmap, colors.ListedColormap):
        # `ListedColormap` does not support lookup table interpolation.
        cmap = colors.LinearSegmentedColormap.from_list('', cmap.colors)
        return cmap(np.linspace(0, 1, N))

    return plt.get_cmap(cmap.name, lut=nlut)(np.linspace(0, 1, N)) 
开发者ID:atmtools,项目名称:typhon,代码行数:39,代码来源:common.py

示例15: register

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import ListedColormap [as 别名]
def register(name=None, cmap=None, path=None):
    if name is None:
        # Self-call to register all colormaps in "ehtplot/color/"
        for name in list_ctab(path=path):
            register(name=name, cmap=cmap, path=path)
    else:
        if cmap is None:
            cmap = ListedColormap(load_ctab(name, path=path))

        # Register the colormap
        register_cmap(name=name, cmap=cmap)

        # Register the reversed colormap
        register_cmap(name=name + ("_r" if unmodified(name) else "r"),
                      cmap=cmap.reversed()) 
开发者ID:liamedeiros,项目名称:ehtplot,代码行数:17,代码来源:core.py


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