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


Python matplotlib.cm方法代码示例

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


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

示例1: apply_cmap

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [as 别名]
def apply_cmap(zs, cmap, vmin=None, vmax=None, unit=None, logrescale=False):
    '''
    apply_cmap(z, cmap) applies the given cmap to the values in z; if vmin and/or vmax are passed,
      they are used to scale z.

    Note that this function can automatically rescale data into log-space if the colormap is a
    neuropythy log-space colormap such as log_eccentricity. To enable this behaviour use the
    optional argument logrescale=True.
    '''
    zs = pimms.mag(zs) if unit is None else pimms.mag(zs, unit)
    zs = np.asarray(zs, dtype='float')
    if pimms.is_str(cmap): cmap = matplotlib.cm.get_cmap(cmap)
    if logrescale:
        if vmin is None: vmin = np.log(np.nanmin(zs))
        if vmax is None: vmax = np.log(np.nanmax(zs))
        mn = np.exp(vmin)
        u = zdivide(nanlog(zs + mn) - vmin, vmax - vmin, null=np.nan)
    else:        
        if vmin is None: vmin = np.nanmin(zs)
        if vmax is None: vmax = np.nanmax(zs)
        u = zdivide(zs - vmin, vmax - vmin, null=np.nan)
    u[np.isnan(u)] = -np.inf
    return cmap(u) 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:25,代码来源:core.py

示例2: plotTZ

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [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

示例3: plotTZ

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [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

示例4: set_cmap

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [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

示例5: spy

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [as 别名]
def spy(Z, precision=0, marker=None, markersize=None, aspect='equal', hold=None, **kwargs):
    ax = gca()
    # allow callers to override the hold state by passing hold=True|False
    washold = ax.ishold()

    if hold is not None:
        ax.hold(hold)
    try:
        ret = ax.spy(Z, precision, marker, markersize, aspect, **kwargs)
        draw_if_interactive()
    finally:
        ax.hold(washold)
    if isinstance(ret, cm.ScalarMappable):
        sci(ret)
    return ret


################# REMAINING CONTENT GENERATED BY boilerplate.py ##############


# This function was autogenerated by boilerplate.py.  Do not edit as
# changes will be lost 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:24,代码来源:pyplot.py

示例6: gci

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [as 别名]
def gci():
    """
    Get the current colorable artist.  Specifically, returns the
    current :class:`~matplotlib.cm.ScalarMappable` instance (image or
    patch collection), or *None* if no images or patch collections
    have been defined.  The commands :func:`~matplotlib.pyplot.imshow`
    and :func:`~matplotlib.pyplot.figimage` create
    :class:`~matplotlib.image.Image` instances, and the commands
    :func:`~matplotlib.pyplot.pcolor` and
    :func:`~matplotlib.pyplot.scatter` create
    :class:`~matplotlib.collections.Collection` instances.  The
    current image is an attribute of the current axes, or the nearest
    earlier axes in the current figure that contains an image.
    """
    return gcf()._gci()


## Any Artist ##


# (getp is simply imported) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:23,代码来源:pyplot.py

示例7: set_cmap

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [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

示例8: init_plot_data

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [as 别名]
def init_plot_data(self):
        a = self.fig.add_subplot(111)

        x = np.arange(120.0) * 2 * np.pi / 60.0
        y = np.arange(100.0) * 2 * np.pi / 50.0
        self.x, self.y = np.meshgrid(x, y)
        z = np.sin(self.x) + np.cos(self.y)
        self.im = a.imshow(z, cmap=cm.RdBu)  # , interpolation='nearest')

        zmax = np.max(z) - ERR_TOL
        ymax_i, xmax_i = np.nonzero(z >= zmax)
        if self.im.origin == 'upper':
            ymax_i = z.shape[0] - ymax_i
        self.lines = a.plot(xmax_i, ymax_i, 'ko')

        self.toolbar.update()  # Not sure why this is needed - ADS 
开发者ID:holzschu,项目名称:python3_ios,代码行数:18,代码来源:embedding_in_wx3_sgskip.py

示例9: test_light_source_topo_surface

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [as 别名]
def test_light_source_topo_surface():
    """Shades a DEM using different v.e.'s and blend modes."""
    fname = cbook.get_sample_data('jacksboro_fault_dem.npz', asfileobj=False)
    dem = np.load(fname)
    elev = dem['elevation']
    # Get the true cellsize in meters for accurate vertical exaggeration
    #   Convert from decimal degrees to meters
    dx, dy = dem['dx'], dem['dy']
    dx = 111320.0 * dx * np.cos(dem['ymin'])
    dy = 111320.0 * dy
    dem.close()

    ls = mcolors.LightSource(315, 45)
    cmap = cm.gist_earth

    fig, axes = plt.subplots(nrows=3, ncols=3)
    for row, mode in zip(axes, ['hsv', 'overlay', 'soft']):
        for ax, ve in zip(row, [0.1, 1, 10]):
            rgb = ls.shade(elev, cmap, vert_exag=ve, dx=dx, dy=dy,
                           blend_mode=mode)
            ax.imshow(rgb)
            ax.set(xticks=[], yticks=[]) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:24,代码来源:test_colors.py

示例10: plot_graph

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [as 别名]
def plot_graph(self, am, position=None, cls=None, fig_name='graph.png'):

        with warnings.catch_warnings():
            warnings.filterwarnings("ignore")

            g = nx.from_numpy_matrix(am)

            if position is None:
                position=nx.drawing.circular_layout(g)

            fig = plt.figure()

            if cls is None:
                cls='r'
            else:
                # Make a user-defined colormap.
                cm1 = mcol.LinearSegmentedColormap.from_list("MyCmapName", ["r", "b"])

                # Make a normalizer that will map the time values from
                # [start_time,end_time+1] -> [0,1].
                cnorm = mcol.Normalize(vmin=0, vmax=1)

                # Turn these into an object that can be used to map time values to colors and
                # can be passed to plt.colorbar().
                cpick = cm.ScalarMappable(norm=cnorm, cmap=cm1)
                cpick.set_array([])
                cls = cpick.to_rgba(cls)
                plt.colorbar(cpick, ax=fig.add_subplot(111))


            nx.draw(g, pos=position, node_color=cls, ax=fig.add_subplot(111))

            fig.savefig(os.path.join(self.plotdir, fig_name)) 
开发者ID:priba,项目名称:nmp_qc,代码行数:35,代码来源:Plotter.py

示例11: scale_for_cmap

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [as 别名]
def scale_for_cmap(cmap, x, vmin=Ellipsis, vmax=Ellipsis, unit=Ellipsis):
    '''
    scale_for_cmap(cmap, x) yields the values in x rescaled to be appropriate for the given
      colormap cmap. The cmap must be the name of a colormap or a colormap object.

    For a given cmap argument, if the object is a colormap itself, it is treated as cmap.name.
    If the cmap names a colormap known to neuropythy, neuropythy will rescale the values in x
    according to a heuristic.
    '''
    import matplotlib as mpl
    if isinstance(cmap, mpl.colors.Colormap): cmap = cmap.name
    (name, cm) = (None, None)
    if cmap not in colormaps:
        for (k,v) in six.iteritems(colormaps):
            if cmap in k:
                (name, cm) = (k, v)
                break
    else: (name, cm) = (cmap, colormaps[cmap])
    if cm is not None:
        cm = cm if len(cm) == 3 else (cm + (None,))
        (cm, (mn,mx), uu) = cm
        if vmin is Ellipsis: vmin = mn
        if vmax is Ellipsis: vmax = mx
        if unit is Ellipsis: unit = uu
    if vmin is Ellipsis: vmin = None
    if vmax is Ellipsis: vmax = None
    if unit is Ellipsis: unit = None
    x = pimms.mag(x) if unit is None else pimms.mag(x, unit)
    if name is not None and name.startswith('log_'):
        emn = np.exp(vmin)
        x = np.log(x + emn)
    vmin = np.nanmin(x) if vmin is None else vmin
    vmax = np.nanmax(x) if vmax is None else vmax
    return zdivide(x - vmin, vmax - vmin, null=np.nan) 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:36,代码来源:core.py

示例12: guess_cortex_cmap

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [as 别名]
def guess_cortex_cmap(pname):
    '''
    guess_cortex_cmap(proptery_name) yields a tuple (cmap, (vmin, vmax)) of a cortical color map
      appropriate to the given property name and the suggested value scaling for the cmap. If the
      given property is not a string or is not recognized then the log_eccentricity axis is used
      and the suggested vmin and vmax are None.
    '''
    import matplotlib as mpl
    if isinstance(pname, mpl.colors.Colormap): pname = pname.name
    if not pimms.is_str(pname): return ('eccenflat', cmap_eccenflat, (None, None), None)
    if pname in colormaps: (cm,cmname) = (colormaps[pname],pname)
    else:
        # check each manually
        cm = None
        for (k,v) in six.iteritems(colormaps):
            if pname.endswith(k):
                (cmname,cm) = (k,v)
                break
        if cm is None:
            for (k,v) in six.iteritems(colormaps):
                if pname.startswith(k):
                    (cmname,cm) = (k,v)
                    break
    # we prefer log-eccentricity when possible
    if cm is None: return ('eccenflat', cmap_eccenflat, (None, None), None)
    if ('log_'+cmname) in colormaps:
        cmname = 'log_'+cmname
        cm = colormaps[cmname]
    return (cmname,) + (cm if len(cm) == 3 else cm + (None,)) 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:31,代码来源:core.py

示例13: list_colormaps

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [as 别名]
def list_colormaps():
    print("{}".format(", ".join([c.strip() for c in cm.cmap_d.keys()])))
    sys.exit(0) 
开发者ID:wdecoster,项目名称:NanoPlot,代码行数:5,代码来源:utils.py

示例14: __init__

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [as 别名]
def __init__(self, alpha=0.5, cmap=None):
        self.alpha = alpha
        self.cm = matplotlib.cm.get_cmap(cmap) 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:5,代码来源:visualize.py

示例15: __call__

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import cm [as 别名]
def __call__(self, image, feature, debug=False):
        _feature = (feature * self.cm.N).astype(np.int)
        heatmap = self.cm(_feature)[:, :, :3] * 255
        heatmap = cv2.resize(heatmap, image.shape[1::-1], interpolation=cv2.INTER_NEAREST)
        canvas = (image * (1 - self.alpha) + heatmap * self.alpha).astype(np.uint8)
        if debug:
            cv2.imshow('max=%f, sum=%f' % (np.max(feature), np.sum(feature)), canvas)
            cv2.waitKey(0)
        return canvas 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:11,代码来源:visualize.py


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