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


Python cm.get_cmap方法代码示例

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


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

示例1: apply_colormap_on_image

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def apply_colormap_on_image(org_im, activation, colormap_name):
    """
        Apply heatmap on image
    Args:
        org_img (PIL img): Original image
        activation_map (numpy arr): Activation map (grayscale) 0-255
        colormap_name (str): Name of the colormap
    """
    # Get colormap
    color_map = mpl_color_map.get_cmap(colormap_name)
    no_trans_heatmap = color_map(activation)

    # Change alpha channel in colormap to make sure original image is displayed
    heatmap = copy.copy(no_trans_heatmap)
    heatmap[:, :, 3] = 0.4
    heatmap = Image.fromarray((heatmap*255).astype(np.uint8))
    no_trans_heatmap = Image.fromarray((no_trans_heatmap*255).astype(np.uint8))

    # Apply heatmap on image
    heatmap_on_image = Image.new("RGBA", org_im.size)
    heatmap_on_image = Image.alpha_composite(heatmap_on_image, org_im.convert('RGBA'))
    heatmap_on_image = Image.alpha_composite(heatmap_on_image, heatmap)
    return no_trans_heatmap, heatmap_on_image 
开发者ID:CMU-CREATE-Lab,项目名称:deep-smoke-machine,代码行数:25,代码来源:viz_functional.py

示例2: plot_bidimensional

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def plot_bidimensional(model, test, recon_error, layer, title):
    bidimensional_data = model.deepfeatures(test, layer).cbind(recon_error).as_data_frame()

    cmap = cm.get_cmap('Spectral')

    fig, ax = plt.subplots()
    bidimensional_data.plot(kind='scatter',
                            x='DF.L{}.C1'.format(layer + 1),
                            y='DF.L{}.C2'.format(layer + 1),
                            s=500,
                            c='Reconstruction.MSE',
                            title=title,
                            ax=ax,
                            colormap=cmap)
    layer_column = 'DF.L{}.C'.format(layer + 1)
    columns = [layer_column + '1', layer_column + '2']
    for k, v in bidimensional_data[columns].iterrows():
        ax.annotate(k, v, size=20, verticalalignment='bottom', horizontalalignment='left')
    fig.canvas.draw()
    plt.show() 
开发者ID:chen0040,项目名称:keras-anomaly-detection,代码行数:22,代码来源:h2o_ecg_pulse_detection.py

示例3: construct_ball_trajectory

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def construct_ball_trajectory(var, r=1., cmap='Blues', start_color=0.4, shape='c'):
    # https://matplotlib.org/examples/color/colormaps_reference.html
    patches = []
    for pos in var:
        if shape == 'c':
            patches.append(mpatches.Circle(pos, r))
        elif shape == 'r':
            patches.append(mpatches.RegularPolygon(pos, 4, r))
        elif shape == 's':
            patches.append(mpatches.RegularPolygon(pos, 6, r))

    colors = np.linspace(start_color, .9, len(patches))
    collection = PatchCollection(patches, cmap=cm.get_cmap(cmap), alpha=1.)
    collection.set_array(np.array(colors))
    collection.set_clim(0, 1)
    return collection 
开发者ID:simonkamronn,项目名称:kvae,代码行数:18,代码来源:plotting.py

示例4: list_of_hex_colours

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def list_of_hex_colours(N, base_cmap):
    """
    Return a list of colors from a colourmap as hex codes

        Arguments:
            cmap: colormap instance, eg. cm.jet.
            N: number of colors.

        Author: FJC
    """
    cmap = _cm.get_cmap(base_cmap, N)

    hex_codes = []
    for i in range(cmap.N):
        rgb = cmap(i)[:3] # will return rgba, we take only first 3 so we get rgb
        hex_codes.append(_mcolors.rgb2hex(rgb))
    return hex_codes 
开发者ID:LSDtopotools,项目名称:LSDMappingTools,代码行数:19,代码来源:colours.py

示例5: cmap_discretize

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def cmap_discretize(N, cmap):
    """Return a discrete colormap from the continuous colormap cmap.

    Arguments:
        cmap: colormap instance, eg. cm.jet.
        N: number of colors.

    Example:
        x = resize(arange(100), (5,100))
        djet = cmap_discretize(cm.jet, 5)
        imshow(x, cmap=djet)
    """

    if type(cmap) == str:
        cmap = _plt.get_cmap(cmap)
    colors_i = _np.concatenate((_np.linspace(0, 1., N), (0.,0.,0.,0.)))
    colors_rgba = cmap(colors_i)
    indices = _np.linspace(0, 1., N+1)
    cdict = {}
    for ki,key in enumerate(('red','green','blue')):
        cdict[key] = [ (indices[i], colors_rgba[i-1,ki], colors_rgba[i,ki])
                       for i in range(N+1) ]
    # Return colormap object.
    return _mcolors.LinearSegmentedColormap(cmap.name + "_%d"%N, cdict, 1024) 
开发者ID:LSDtopotools,项目名称:LSDMappingTools,代码行数:26,代码来源:colours.py

示例6: __init__

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def __init__(self, cmap, levels):

        if isinstance(cmap, str):
            self.cmap = _cm.get_cmap(cmap)
        elif isinstance(cmap, _mcolors.Colormap):
            self.cmap = cmap
        else:
            raise ValueError('Colourmap must either be a string name of a colormap, \
                         or a Colormap object (class instance). Please try again.' \
                         "Colourmap supplied is of type: ", type(cmap))

        self.N = self.cmap.N
        self.monochrome = self.cmap.monochrome
        self.levels = _np.asarray(levels)#, dtype='float64')
        self._x = self.levels
        self.levmax = self.levels.max()
        self.levmin = self.levels.min()
        self.transformed_levels = _np.linspace(self.levmin, self.levmax,
             len(self.levels)) 
开发者ID:LSDtopotools,项目名称:LSDMappingTools,代码行数:21,代码来源:colours.py

示例7: plotTZ

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def plotTZ(filename=None):
    t = np.linspace(0, 1, 101)
    z = 0.25 + 0.5 / (1 + np.exp(- 20 * (t - 0.5))) + 0.05 * np.cos(t * 2 * np.pi)
    cmap = cm.get_cmap('cool')
    fig, (ax1, ax2) = plt.subplots(1, 2, gridspec_kw = {'width_ratios':[19, 1]})
    poly1 = [[0, 0]]
    poly1.extend([[t[i], z[i]] for i in range(t.size)])
    poly1.extend([[1, 0], [0, 0]])
    poly2 = [[0, 1]]
    poly2.extend([[t[i], z[i]] for i in range(t.size)])
    poly2.extend([[1, 1], [0, 1]])
    poly1 = plt.Polygon(poly1,fc=cmap(0.0))
    poly2 = plt.Polygon(poly2,fc=cmap(1.0))
    ax1.add_patch(poly1)
    ax1.add_patch(poly2)
    ax1.set_xlabel('x1', size=22)
    ax1.set_ylabel('x2', size=22)
    ax1.set_title('True Data', size=28)
    colorbar.ColorbarBase(ax2, cmap=cmap, format='%.1f')
    ax2.set_ylabel('Output y', size=22)
    plt.show()
    if not filename is None:
        plt.savefig(filename, format="pdf", bbox_inches="tight")
        plt.close() 
开发者ID:sato9hara,项目名称:defragTrees,代码行数:26,代码来源:paper_synthetic2.py

示例8: plotTZ

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def plotTZ(filename=None):
    cmap = cm.get_cmap('cool')
    fig, (ax1, ax2) = plt.subplots(1, 2, gridspec_kw = {'width_ratios':[19, 1]})
    ax1.add_patch(pl.Rectangle(xy=[0, 0], width=0.5, height=0.5, facecolor=cmap(0.0), linewidth='2.0'))
    ax1.add_patch(pl.Rectangle(xy=[0.5, 0.5], width=0.5, height=0.5, facecolor=cmap(0.0), linewidth='2.0'))
    ax1.add_patch(pl.Rectangle(xy=[0, 0.5], width=0.5, height=0.5, facecolor=cmap(1.0), linewidth='2.0'))
    ax1.add_patch(pl.Rectangle(xy=[0.5, 0], width=0.5, height=0.5, facecolor=cmap(1.0), linewidth='2.0'))
    ax1.set_xlabel('x1', size=22)
    ax1.set_ylabel('x2', size=22)
    ax1.set_title('True Data', size=28)
    colorbar.ColorbarBase(ax2, cmap=cmap, format='%.1f')
    ax2.set_ylabel('Output y', size=22)
    plt.show()
    if not filename is None:
        plt.savefig(filename, format="pdf", bbox_inches="tight")
        plt.close() 
开发者ID:sato9hara,项目名称:defragTrees,代码行数:18,代码来源:paper_synthetic1.py

示例9: set_cmap

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def set_cmap(cmap):
    """
    Set the default colormap.  Applies to the current image if any.
    See help(colormaps) for more information.

    *cmap* must be a :class:`~matplotlib.colors.Colormap` instance, or
    the name of a registered colormap.

    See :func:`matplotlib.cm.register_cmap` and
    :func:`matplotlib.cm.get_cmap`.
    """
    cmap = cm.get_cmap(cmap)

    rc('image', cmap=cmap.name)
    im = gci()

    if im is not None:
        im.set_cmap(cmap)

    draw_if_interactive() 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:22,代码来源:pyplot.py

示例10: colorbar

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def colorbar(mappable, cax=None, ax=None, **kw):
    """
    Create a colorbar for a ScalarMappable instance.

    Documentation for the pylab thin wrapper:
    %(colorbar_doc)s
    """
    import matplotlib.pyplot as plt
    if ax is None:
        ax = plt.gca()
    if cax is None:
        cax, kw = make_axes(ax, **kw)
    cax.hold(True)
    cb = Colorbar(cax, mappable, **kw)

    def on_changed(m):
        cb.set_cmap(m.get_cmap())
        cb.set_clim(m.get_clim())
        cb.update_bruteforce(m)

    cbid = mappable.callbacksSM.connect('changed', on_changed)
    mappable.colorbar = cb
    ax.figure.sca(ax)
    return cb 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:26,代码来源:colorbar.py

示例11: _get_cmap_norms

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def _get_cmap_norms():
    """
    Define a colormap and appropriate norms for each of the four
    possible settings of the extend keyword.

    Helper function for _colorbar_extension_shape and
    colorbar_extension_length.
    """
    # Create a color map and specify the levels it represents.
    cmap = get_cmap("RdBu", lut=5)
    clevs = [-5., -2.5, -.5, .5, 1.5, 3.5]
    # Define norms for the color maps.
    norms = dict()
    norms['neither'] = BoundaryNorm(clevs, len(clevs) - 1)
    norms['min'] = BoundaryNorm([-10] + clevs[1:], len(clevs) - 1)
    norms['max'] = BoundaryNorm(clevs[:-1] + [10], len(clevs) - 1)
    norms['both'] = BoundaryNorm([-10] + clevs[1:-1] + [10], len(clevs) - 1)
    return cmap, norms 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:20,代码来源:test_colorbar.py

示例12: set_oggm_cmaps

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def set_oggm_cmaps(use_hcl=None):
    # Set global colormaps
    global OGGM_CMAPS

    if use_hcl is None:
        use_hcl = HAS_HCL_CMAP

    OGGM_CMAPS['terrain'] = colormap.terrain
    if HAS_HCL_CMAP and use_hcl:
        cm_divs = 100  # number of discrete colours from continuous colormaps
        tcmap = sequential_hcl("Blue-Yellow", rev=True).cmap(cm_divs)
        OGGM_CMAPS['section_thickness'] = tcmap
        OGGM_CMAPS['glacier_thickness'] = tcmap
    else:
        OGGM_CMAPS['section_thickness'] = plt.cm.get_cmap('YlOrRd')
        OGGM_CMAPS['glacier_thickness'] = plt.get_cmap('viridis') 
开发者ID:OGGM,项目名称:oggm,代码行数:18,代码来源:graphics.py

示例13: _get_map_plot_options

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def _get_map_plot_options(self, map_name):
        cmap = get_cmap(self._get_map_attr(map_name, 'colormap', self._plot_config.colormap))

        masked_color = self._get_map_attr(map_name, 'colormap_masked_color', self._plot_config.colormap_masked_color)
        if masked_color is not None:
            cmap.set_bad(color=masked_color)

        output_dict = {'vmin': self._data_info.get_single_map_info(map_name).min(),
                       'vmax': self._data_info.get_single_map_info(map_name).max(),
                       'cmap': cmap}

        scale = self._get_map_attr(map_name, 'scale', Scale())
        if scale.use_max:
            output_dict['vmax'] = scale.vmax
        if scale.use_min:
            output_dict['vmin'] = scale.vmin

        return output_dict 
开发者ID:robbert-harms,项目名称:MDT,代码行数:20,代码来源:matplotlib_renderer.py

示例14: set_cmap

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def set_cmap(cmap):
    """
    Set the default colormap.  Applies to the current image if any.
    See help(colormaps) for more information.

    *cmap* must be a :class:`~matplotlib.colors.Colormap` instance, or
    the name of a registered colormap.

    See :func:`matplotlib.cm.register_cmap` and
    :func:`matplotlib.cm.get_cmap`.
    """
    cmap = cm.get_cmap(cmap)

    rc('image', cmap=cmap.name)
    im = gci()

    if im is not None:
        im.set_cmap(cmap) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:20,代码来源:pyplot.py

示例15: colorbar

# 需要导入模块: from matplotlib import cm [as 别名]
# 或者: from matplotlib.cm import get_cmap [as 别名]
def colorbar(mappable, cax=None, ax=None, **kw):
    """
    Create a colorbar for a ScalarMappable instance.

    Documentation for the pyplot thin wrapper:

    %s
    """
    import matplotlib.pyplot as plt
    if ax is None:
        ax = plt.gca()
    if cax is None:
        cax, kw = make_axes(ax, **kw)
    cb = Colorbar(cax, mappable, **kw)

    def on_changed(m):
        cb.set_cmap(m.get_cmap())
        cb.set_clim(m.get_clim())
        cb.update_bruteforce(m)

    cbid = mappable.callbacksSM.connect('changed', on_changed)
    mappable.colorbar = cb
    ax.figure.sca(ax)
    return cb 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:26,代码来源:colorbar.py


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