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


Python pyplot.cm方法代码示例

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


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

示例1: __init__

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import cm [as 别名]
def __init__(self, cbar, mappable):
        self.cbar = cbar
        self.mappable = mappable
        self.press = None
        self.cycle = sorted([i for i in dir(plt.cm) if hasattr(getattr(plt.cm, i), 'N')])
        self.index = self.cycle.index(cbar.get_cmap().name) 
开发者ID:Kirubaharan,项目名称:hydrology,代码行数:8,代码来源:checkdam.py

示例2: squaremesh

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import cm [as 别名]
def squaremesh(mesh, prop, cmap=pyplot.cm.jet, vmin=None, vmax=None):
    """
    Make a pseudo-color plot of a mesh of squares

    Parameters:

    * mesh : :class:`geoist.mesher.SquareMesh` or compatible
        The mesh (a compatible mesh must implement the methods ``get_xs`` and
        ``get_ys``)
    * prop : str
        The physical property of the squares to use as the color scale.
    * cmap : colormap
        Color map to be used. (see pyplot.cm module)
    * vmin, vmax : float
        Saturation values of the colorbar.

    Returns:

    * axes : ``matplitlib.axes``
        The axes element of the plot

    """
    if prop not in mesh.props:
        raise ValueError("Can't plot because 'mesh' doesn't have property '%s'"
                         % (prop))
    xs = mesh.get_xs()
    ys = mesh.get_ys()
    X, Y = numpy.meshgrid(xs, ys)
    V = numpy.reshape(mesh.props[prop], mesh.shape)
    plot = pyplot.pcolor(X, Y, V, cmap=cmap, vmin=vmin, vmax=vmax, picker=True)
    pyplot.xlim(xs.min(), xs.max())
    pyplot.ylim(ys.min(), ys.max())
    return plot 
开发者ID:igp-gravity,项目名称:geoist,代码行数:35,代码来源:giplt.py

示例3: seismic_image

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import cm [as 别名]
def seismic_image(section, dt, ranges=None, cmap=pyplot.cm.gray,
                  aspect=None, vmin=None, vmax=None):
    """
    Plot a seismic section (numpy 2D array matrix) as an image.

    Parameters:

    * section :  2D array
        matrix of traces (first dimension time, second dimension traces)
    * dt : float
        sample rate in seconds
    * ranges : (x1, x2)
        min and max horizontal coordinate values (default trace number)
    * cmap : colormap
        color map to be used. (see pyplot.cm module)
    * aspect : float
        matplotlib imshow aspect parameter, ratio between axes
    * vmin, vmax : float
        min and max values for imshow

    """
    npts, maxtraces = section.shape  # time/traces
    if maxtraces < 1:
        raise IndexError("Nothing to plot")
    if npts < 1:
        raise IndexError("Nothing to plot")
    t = numpy.linspace(0, dt*npts, npts)
    data = section
    if ranges is None:
        ranges = (0, maxtraces)
    x0, x1 = ranges
    extent = (x0, x1, t[-1:], t[0])
    if aspect is None:  # guarantee a rectangular picture
        aspect = numpy.round((x1 - x0)/numpy.max(t))
        aspect -= aspect*0.2
    if vmin is None and vmax is None:
        scale = numpy.abs([section.max(), section.min()]).max()
        vmin = -scale
        vmax = scale
    pyplot.imshow(data, aspect=aspect, cmap=cmap, origin='upper',
                  extent=extent, vmin=vmin, vmax=vmax) 
开发者ID:igp-gravity,项目名称:geoist,代码行数:43,代码来源:giplt.py

示例4: read_correct_ch_dam_data

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import cm [as 别名]
def read_correct_ch_dam_data(csv_file, calibration_slope, calibration_intercept, stage_cutoff=0.1):
    """
    Function to read and calibrate odyssey capacitance sensor data

    :param csv_file: csv file created from sensor
    :param calibration_slope: slope
    :param calibration_intercept: intercept
    :return: calibrated and time corrected data

    Examples:
        >>> read_correct_ch_dam_data(csv_file=file.csv, calibration_slope=0.111, calibration_intercept=0.222)
    """
    water_level = pd.read_csv(csv_file, skiprows=9, sep=',', header=0,
                              names=['scan no', 'date', 'time', 'raw value', 'calibrated value'])
    water_level['calibrated value'] = (water_level['raw value'] * calibration_slope) + calibration_intercept  # in cm
    # water_level['calibrated value'] = np.round(water_level['calibrated value']/resolution_ody)*resolution_ody
    water_level['calibrated value'] /= 1000.0
    water_level['calibrated value'] = myround(a=water_level['calibrated value'], decimals=3)
    # #change the column name
    water_level.columns.values[4] = 'stage(m)'
    # print water_level.head()

    # create date time index
    format = '%d/%m/%Y  %H:%M:%S'
    c_str = ' 24:00:00'
    for index, row in water_level.iterrows():
        x_str = row['time']
        if x_str == c_str:
            # convert string to datetime object
            r_date = pd.to_datetime(row['date'], format='%d/%m/%Y ')
            # add 1 day
            c_date = r_date + timedelta(days=1)
            # convert datetime to string
            c_date = c_date.strftime('%d/%m/%Y ')
            c_time = ' 00:00:00'
            # water_level.loc[:, ('date', index)] = c_date
            # water_level.loc[:, ('time', index)] = c_time
            water_level.loc[index,'date'] = c_date
            water_level.loc[index,'time'] = c_time

    water_level['date_time'] = pd.to_datetime(water_level['date'] + water_level['time'], format=format)
    water_level.set_index(water_level['date_time'], inplace=True)
    # # drop unneccessary columns before datetime aggregation
    for index, row in water_level.iterrows():
        # print row
        obs_stage = row['stage(m)']
        if obs_stage < stage_cutoff:
            # water_level.loc[:, ('stage(m)', index.strftime(date_format))] = 0.0
            water_level.loc[index,'stage(m)'] = 0.0

    water_level.drop(['scan no', 'date', 'time', 'date_time'], inplace=True, axis=1)

    return water_level 
开发者ID:Kirubaharan,项目名称:hydrology,代码行数:55,代码来源:checkdam.py

示例5: register_cptcity_cmaps

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import cm [as 别名]
def register_cptcity_cmaps(cptcitycmaps, urlkw={}, cmapnamekw={}):
    """Register cpt-city colormaps from a list of URLs and/or files to the current plt.cm space
    
    Parameters
    ----------
    cptcitycmaps : str, dict, or list
        str will be interpreted as path to scan for .cpt files
        list over file names or urls to .cpt files
        dict can be used to provide (name : fname/url) mappings
    urlkw : dict
        keyword arguments passed to cmap_from_cptcity_url

    Usage
    -----
    To register a set of color maps, use, e.g.
        
        register_cptcity_cmaps({'ncl_cosam' : "http://soliton.vm.bytemark.co.uk/pub/cpt-city/ncl/cosam.cpt"})

    Retrieve the cmap using,
    
        plt.cm.get_cmap('ncl_cosam')

    """
    def _register_with_reverse(cmap):
        plt.cm.register_cmap(cmap=cmap)
        plt.cm.register_cmap(cmap=modify.reverse_cmap(cmap))

    def _try_reading_methods(cmapfile, cmapname=None):
        try:
            return gmtColormap(cmapfile, name=cmapname)
        except IOError:
            try:
                return cmap_from_cptcity_url(cmapfile, name=cmapname, **urlkw) 
            except:
                raise

    if isinstance(cptcitycmaps, str):
        if cptcitycmaps.endswith('.cpt'):
            cptcitycmaps = [cptcitycmaps]
        else:
            cptcitycmaps = find_cpt_files(cptcitycmaps, **cmapnamekw)

    cmaps = []

    if isinstance(cptcitycmaps, dict):
        for cmapname, cmapfile in cptcitycmaps.items():
            cmap = _try_reading_methods(cmapfile, cmapname)
            _register_with_reverse(cmap)
            cmaps.append(cmap)
    else:
        for cmapfile in cptcitycmaps:
            cmap = _try_reading_methods(cmapfile)
            _register_with_reverse(cmap)
            cmaps.append(cmap)

    return cmaps 
开发者ID:j08lue,项目名称:pycpt,代码行数:58,代码来源:load.py

示例6: contourf

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import cm [as 别名]
def contourf(x, y, v, shape, levels, interp=False, extrapolate=False,
             vmin=None, vmax=None, cmap=pyplot.cm.jet, basemap=None):
    """
    Make a filled contour plot of the data.

    Parameters:

    * x, y : array
        Arrays with the x and y coordinates of the grid points. If the data is
        on a regular grid, then assume x varies first (ie, inner loop), then y.
    * v : array
        The scalar value assigned to the grid points.
    * shape : tuple = (ny, nx)
        Shape of the regular grid.
        If interpolation is not False, then will use *shape* to grid the data.
    * levels : int or list
        Number of contours to use or a list with the contour values.
    * interp : True or False
        Wether or not to interpolate before trying to plot. If data is not on
        regular grid, set to True!
    * extrapolate : True or False
        Wether or not to extrapolate the data when interp=True
    * vmin, vmax
        Saturation values of the colorbar. If provided, will overwrite what is
        set by *levels*.
    * cmap : colormap
        Color map to be used. (see pyplot.cm module)
    * basemap : mpl_toolkits.basemap.Basemap
        If not None, will use this basemap for plotting with a map projection
        (see :func:`~geoist.vis.giplt.basemap` for creating basemaps)

    Returns:

    * levels : list
        List with the values of the contour levels

    """
    if x.shape != y.shape != v.shape:
        raise ValueError("Input arrays x, y, and v must have same shape!")
    if interp:
        x, y, v = gridder.interp(x, y, v, shape, extrapolate=extrapolate)
    X = numpy.reshape(x, shape)
    Y = numpy.reshape(y, shape)
    V = numpy.reshape(v, shape)
    kwargs = dict(vmin=vmin, vmax=vmax, cmap=cmap)
    #kwargs = dict(vmin=vmin, vmax=vmax, cmap=cmap, picker=True)
    if basemap is None:
        ct_data = pyplot.contourf(X, Y, V, levels, **kwargs)
        pyplot.xlim(X.min(), X.max())
        pyplot.ylim(Y.min(), Y.max())
    else:
        lon, lat = basemap(X, Y)
        ct_data = basemap.contourf(lon, lat, V, levels, **kwargs)
    return ct_data.levels 
开发者ID:igp-gravity,项目名称:geoist,代码行数:56,代码来源:giplt.py

示例7: pcolor

# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import cm [as 别名]
def pcolor(x, y, v, shape, interp=False, extrapolate=False, cmap=pyplot.cm.jet,
           vmin=None, vmax=None, basemap=None):
    """
    Make a pseudo-color plot of the data.

    Parameters:

    * x, y : array
        Arrays with the x and y coordinates of the grid points. If the data is
        on a regular grid, then assume x varies first (ie, inner loop), then y.
    * v : array
        The scalar value assigned to the grid points.
    * shape : tuple = (ny, nx)
        Shape of the regular grid.
        If interpolation is not False, then will use *shape* to grid the data.
    * interp : True or False
        Wether or not to interpolate before trying to plot. If data is not on
        regular grid, set to True!
    * extrapolate : True or False
        Wether or not to extrapolate the data when interp=True
    * cmap : colormap
        Color map to be used. (see pyplot.cm module)
    * vmin, vmax
        Saturation values of the colorbar.
    * basemap : mpl_toolkits.basemap.Basemap
        If not None, will use this basemap for plotting with a map projection
        (see :func:`~geoist.vis.giplt.basemap` for creating basemaps)

    Returns:

    * axes : ``matplitlib.axes``
        The axes element of the plot

    """
    if x.shape != y.shape != v.shape:
        raise ValueError("Input arrays x, y, and v must have same shape!")
    if vmin is None:
        vmin = v.min()
    if vmax is None:
        vmax = v.max()
    if interp:
        x, y, v = gridder.interp(x, y, v, shape, extrapolate=extrapolate)
    X = numpy.reshape(x, shape)
    Y = numpy.reshape(y, shape)
    V = numpy.reshape(v, shape)
    if basemap is None:
        plot = pyplot.pcolor(X, Y, V, cmap=cmap, vmin=vmin, vmax=vmax,
                             picker=True)
        pyplot.xlim(X.min(), X.max())
        pyplot.ylim(Y.min(), Y.max())
    else:
        lon, lat = basemap(X, Y)
        plot = basemap.pcolor(lon, lat, V, cmap=cmap, vmin=vmin, vmax=vmax,
                              picker=True)
    return plot 
开发者ID:igp-gravity,项目名称:geoist,代码行数:57,代码来源:giplt.py


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