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


Python LightSource.shade方法代码示例

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


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

示例1: draw_figure

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
    def draw_figure(self):
        ls = LightSource(azdeg=315, altdeg=45)
        self.surf = self.data

        # try to plot the whole array
        try:
            blended_surface = ls.shade(self.surf, cmap=self.colormap, vert_exag=5, blend_mode=b"overlay",
                                       vmin=np.nanmin(self.surf), vmax=np.nanmax(self.surf))
        # too big, two attempts for sub-sampling
        except MemoryError:
            rows = self.data.shape[0]
            cols = self.data.shape[1]

            # 1st attempt: <= 1024x1024
            try:
                max_elements = 1024
                row_stride = rows // max_elements + 1
                col_stride = cols // max_elements + 1
                self.surf = self.data[::row_stride, ::col_stride]
                blended_surface = ls.shade(self.surf, cmap=self.colormap, vert_exag=5, blend_mode=b"overlay",
                                           vmin=np.nanmin(self.surf), vmax=np.nanmax(self.surf))

            except MemoryError:
                # 2st attempt: <= 512x512
                max_elements = 512
                row_stride = rows // max_elements + 1
                col_stride = cols // max_elements + 1
                self.surf = self.data[::row_stride, ::col_stride]
                blended_surface = ls.shade(self.surf, cmap=self.colormap, vert_exag=5, blend_mode=b"overlay",
                                           vmin=np.nanmin(self.surf), vmax=np.nanmax(self.surf))

            log.debug("too big: %s x %s > subsampled to %s x %s"
                      % (self.data.shape[0], self.data.shape[1], self.surf.shape[0], self.surf.shape[1]))

        self.axes.coastlines(resolution='50m', color='gray', linewidth=1)
        img = self.axes.imshow(blended_surface, origin='lower', cmap=self.colormap,
                               extent=self.geo_extent, transform=ccrs.PlateCarree())
        img.set_clim(vmin=np.nanmin(self.surf), vmax=np.nanmax(self.surf))
        # add gridlines with labels only on the left and on the bottom
        grl = self.axes.gridlines(crs=ccrs.PlateCarree(), color='gray', draw_labels=True)
        grl.xformatter = LONGITUDE_FORMATTER
        grl.yformatter = LATITUDE_FORMATTER
        grl.xlabel_style = {'size': 8}
        grl.ylabel_style = {'size': 8}
        grl.ylabels_right = False
        grl.xlabels_top = False

        if self.cb:
            self.cb.on_mappable_changed(img)
        else:
            self.cb = plt.colorbar(img, ax=self.axes)
        self.cb.ax.tick_params(labelsize=8)
开发者ID:HDFGroup,项目名称:hdf-compass,代码行数:54,代码来源:plot.py

示例2: SurfPlot

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
def SurfPlot(data):
    from mpl_toolkits.mplot3d import Axes3D
    from matplotlib import cbook
    from matplotlib import cm
    from matplotlib.colors import LightSource
    import matplotlib.pyplot as plt
    import numpy as np

    ncols, nrows = data.shape
    if ncols * nrows > 20000: print 'Warning, surface plotting things of this size is slow...'
    z = data
    x = np.linspace(0, ncols, ncols)
    y = np.linspace(0, nrows, nrows)
    x, y = np.meshgrid(x, y)
    
    region = np.s_[0:min(ncols,nrows), 0:min(ncols,nrows)]
    x, y, z = x[region], y[region], z[region]

    fig, ax = plt.subplots(subplot_kw=dict(projection='3d'), figsize=(10,10))

    ls = LightSource(270, 45)
    # To use a custom hillshading mode, override the built-in shading and pass
    # in the rgb colors of the shaded surface calculated from "shade".
    rgb = ls.shade(z, cmap=cm.CMRmap, vert_exag=0.01, blend_mode='soft')
    surf = ax.plot_surface(x, y, z, rstride=1, cstride=1, facecolors=rgb, linewidth=0, antialiased=True, shade=False)
    plt.show()
开发者ID:lsst-dm,项目名称:calibration-scripts,代码行数:28,代码来源:functions.py

示例3: test_light_source_shading_color_range

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
def test_light_source_shading_color_range():
    # see also
    #http://matplotlib.org/examples/pylab_examples/shading_example.html

    from matplotlib.colors import LightSource
    from matplotlib.colors import Normalize

    refinput = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
    norm = Normalize(vmin=0, vmax=50)
    ls = LightSource(azdeg=0, altdeg=65)
    testoutput = ls.shade(refinput, plt.cm.jet, norm=norm)
    refoutput = np.array([
        [[0., 0., 0.58912656, 1.],
        [0., 0., 0.67825312, 1.],
        [0., 0., 0.76737968, 1.],
        [0., 0., 0.85650624, 1.]],
        [[0., 0., 0.9456328, 1.],
        [0., 0., 1., 1.],
        [0., 0.04901961, 1., 1.],
        [0., 0.12745098, 1., 1.]],
        [[0., 0.22156863, 1., 1.],
        [0., 0.3, 1., 1.],
        [0., 0.37843137, 1., 1.],
        [0., 0.45686275, 1., 1.]]
        ])
    assert_array_almost_equal(refoutput, testoutput)
开发者ID:NHades,项目名称:matplotlib,代码行数:28,代码来源:test_colors.py

示例4: plot_shaded

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
    def plot_shaded(self, cmap=plt.cm.terrain, lightsource_kwargs=None, *args, **kwargs):

        if lightsource_kwargs is None:
            lightsource_kwargs = {'azdeg':225, 'altdeg':5}

        extent = [self.x.min(), self.x.max(), self.y.min(), self.y.max()]

        arr = self.z.copy()
        nan_mask = np.isnan(arr)
        arr_min = arr[~nan_mask].min()
        if nan_mask.any():
            arr[nan_mask] = max(arr_min-10, 0)

        ls = LightSource(**lightsource_kwargs)
        shaded = ls.shade(arr, cmap=cmap)

        fig = plt.figure()
        ax = fig.add_subplot(111)

        im = ax.imshow(shaded, cmap=cmap, extent=extent, *args, **kwargs)
        plt.colorbar(im)

        ax.get_xaxis().get_major_formatter().set_useOffset(False)
        ax.get_yaxis().get_major_formatter().set_useOffset(False)

        plt.show()
开发者ID:Ffisegydd,项目名称:pylidar,代码行数:28,代码来源:core.py

示例5: main

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
def main():

    fig, ax = plt.subplots(3, 2, figsize=(7, 10))
    fig.tight_layout()    

    if 1:
        # Same terrain and data.
        data = make_test_data('circles', noise_factor=0.05) * 2 - 7
        terrain = data
    else:
        # Different terrain and data. Matplotlib hill shading can only show the data.
        data = make_test_data('hills') * -1
        terrain = make_test_data('circles', noise_factor=0.05) * 2
        
    assert terrain.shape == data.shape, "{} != {}".format(terrain.shape, data.shape)
    print("data range: {} {}".format(np.min(data), np.max(data)))
    
    if len(sys.argv) > 1:
        cmap_name = sys.argv[1]
    else:
        #cmap_name = 'copper' # from http://matplotlib.org/examples/pylab_examples/shading_example.html?highlight=codex%20shade
        #cmap_name = 'gist_earth' # works reasonably fine with all of them
        cmap_name = 'bwr'        # shows that mpl & pegtop don't work when there is no increasing intensity
        #cmap_name = 'cubehelix'  # shows that HSV blending does not work were color is black
        #cmap_name = 'rainbow'    # shows that mpl & pegtop don't work when there is no increasing intensity
        #cmap_name = 'Paired_r'   # is nice to inspect when the data is different from the terrain
        
    print ("Using colormap: {!r}".format(cmap_name))
    cmap = plt.cm.get_cmap(cmap_name)
    cmap.set_bad('cyan')
    cmap.set_over('cyan')
    cmap.set_under('cyan')
    
    abs_max = np.max(np.abs(data)) # force color bar to be symmetrical. 
    norm = mpl.colors.Normalize(vmin=-abs_max, vmax=abs_max)
    #norm = mpl.colors.Normalize(vmin=-2, vmax=3)
    
    draw(ax[0, 0], cmap=cmap, norm=norm, title='No shading', 
         image_data = data)

    draw(ax[0, 1], cmap=plt.cm.gray, title='Matplotlib intensity', 
         image_data = mpl_surface_intensity(terrain))

    ls = LightSource(azdeg=DEF_AZIMUTH, altdeg=DEF_ELEVATION)
    draw(ax[1, 0], cmap=cmap, norm=norm, title='Matplotlib hill shading', 
         image_data = ls.shade(data, cmap=cmap, norm=norm))
    
    draw(ax[1, 1], cmap=cmap, norm=norm, title='Pegtop blending', 
         image_data = mpl_hill_shade(data, terrain=terrain,  
                                     cmap=cmap, norm=norm, blend_function=pegtop_blending))
    
    draw(ax[2, 0], cmap=cmap, norm=norm, title='RGB blending', 
         image_data = mpl_hill_shade(data, terrain=terrain, 
                                     cmap=cmap, norm=norm, blend_function=rgb_blending))    
    
    draw(ax[2, 1], cmap=cmap, norm=norm, title='HSV blending', 
         image_data = mpl_hill_shade(data, terrain=terrain, 
                                     cmap=cmap, norm=norm, blend_function=hsv_blending))    

    plt.show()
开发者ID:titusjan,项目名称:hill_shading,代码行数:62,代码来源:compare_blending.py

示例6: background_map

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
 def background_map(self, ax):
     llcrnrlat, urcrnrlat, llcrnrlon, urcrnrlon, lat_ts = (31, 44, -126, -113, 37.5)
     m = Basemap(projection='merc', llcrnrlat=llcrnrlat,
                 urcrnrlat=urcrnrlat, llcrnrlon=llcrnrlon, urcrnrlon=urcrnrlon,
                 lat_ts=lat_ts, resolution='i', ax=ax)
     m.drawmapboundary(fill_color='lightblue', zorder=0)
     m.fillcontinents(zorder=0)
     etopofn = '/home/behry/uni/data/etopo1_central_europe_gmt.grd'
     etopodata = Dataset(etopofn, 'r')
     z = etopodata.variables['z'][:]
     x_range = etopodata.variables['x_range'][:]
     y_range = etopodata.variables['y_range'][:]
     spc = etopodata.variables['spacing'][:]
     lats = np.arange(y_range[0], y_range[1], spc[1])
     lons = np.arange(x_range[0], x_range[1], spc[0])
     topoin = z.reshape(lats.size, lons.size, order='C')
     # transform to nx x ny regularly spaced 5km native projection grid
     nx = int((m.xmax - m.xmin) / 5000.) + 1; ny = int((m.ymax - m.ymin) / 5000.) + 1
     topodat, x, y = m.transform_scalar(np.flipud(topoin), lons, lats, nx, ny, returnxy=True)
     ls = LightSource(azdeg=300, altdeg=15, hsv_min_sat=0.2, hsv_max_sat=0.3,
                      hsv_min_val=0.2, hsv_max_val=0.3)
     # shade data, creating an rgb array.
     rgb = ls.shade(np.ma.masked_less(topodat / 1000.0, 0.0), cm.gist_gray_r)
     m.imshow(rgb)
     m.drawmeridians(np.arange(6, 12, 2), labels=[0, 0, 0, 1], color='white',
                     linewidth=0.5, zorder=0)
     m.drawparallels(np.arange(44, 50, 2), labels=[1, 0, 0, 0], color='white',
                     linewidth=0.5, zorder=0)
     m.drawcoastlines(zorder=1)
     m.drawcountries(linewidth=1.5, zorder=1)
     m.drawstates()
     m.drawrivers(color='lightblue', zorder=1)
     return m
开发者ID:FMassin,项目名称:SRL_2015,代码行数:35,代码来源:eewvs_alert_times.py

示例7: apply

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
    def apply(self):
        from mpl_toolkits.basemap import shiftgrid, cm
        common.ShowQuestion
        display = self.VpyartDisplay.value
        if (isinstance(display, pyart.graph.RadarMapDisplay) or
            isinstance(display, pyart.graph.GridMapDisplay)):
            pass
        elif (isinstance(display, pyart.graph.RadarDisplay) or
              isinstance(display, pyart.graph.AirborneRadarDisplay)):
            common.ShowWarning(
                "Topography require a MapDisplay, be sure to "
                "check the 'use MapDisplay' box in the 'Display Options' Menu")
            return
        else:
            common.ShowWarning(
                "Need a pyart display instance, be sure to "
                "link this components (%s), to a radar or grid display" %
                self.name)
            return

        filename = str(self.lineEdit.text())
        if filename != self.current_open:
            if filename.startswith("http"):
                resp = common.ShowQuestion(
                    "Loading a file from the internet may take long." +
                    " Are you sure you want to continue?")
                if resp != QtWidgets.QMessageBox.Ok:
                    return
            self.etopodata = Dataset(filename)
            self.current_open = filename

        topoin = np.maximum(0, self.etopodata.variables['ROSE'][:])
        lons = self.etopodata.variables['ETOPO05_X'][:]
        lats = self.etopodata.variables['ETOPO05_Y'][:]
        # shift data so lons go from -180 to 180 instead of 20 to 380.
        topoin, lons = shiftgrid(180., topoin, lons, start=False)

        # plot topography/bathymetry as an image.

        # create the figure and axes instances.
        # setup of basemap ('lcc' = lambert conformal conic).
        # use major and minor sphere radii from WGS84 ellipsoid.
        m = self.VpyartDisplay.value.basemap
        # transform to nx x ny regularly spaced 5km native projection grid
        nx = int((m.xmax - m.xmin)/500.) + 1
        ny = int((m.ymax - m.ymin)/500.) + 1
        topodat = m.transform_scalar(topoin, lons, lats, nx, ny)
        # plot image over map with imshow.

        # draw coastlines and political boundaries.

        ls = LightSource(azdeg=90, altdeg=20)
        # convert data to rgb array including shading from light source.
        # (must specify color map)
        rgb = ls.shade(topodat, cm.GMT_relief)
        im = m.imshow(rgb)

        self.VpyartDisplay.update(strong=False)
开发者ID:gamaanderson,项目名称:artview,代码行数:60,代码来源:background.py

示例8: avoid_outliers

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
def avoid_outliers():
    """Use a custom norm to control the displayed z-range of a shaded plot."""
    y, x = np.mgrid[-4:2:200j, -4:2:200j]
    z = 10 * np.cos(x**2 + y**2)

    # Add some outliers...
    z[100, 105] = 2000
    z[120, 110] = -9000

    ls = LightSource(315, 45)
    fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4.5))

    rgb = ls.shade(z, plt.cm.copper)
    ax1.imshow(rgb)
    ax1.set_title('Full range of data')

    rgb = ls.shade(z, plt.cm.copper, vmin=-10, vmax=10)
    ax2.imshow(rgb)
    ax2.set_title('Manually set range')

    fig.suptitle('Avoiding Outliers in Shaded Plots', size='x-large')
开发者ID:717524640,项目名称:matplotlib,代码行数:23,代码来源:advanced_hillshading.py

示例9: plotRainbow

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
 def plotRainbow(self):
     
     self.setUp()
     
     ls = LightSource(270, 45)
     # To use a custom hillshading mode, override the built-in shading and pass
     # in the rgb colors of the shaded surface calculated from "shade".
     rgb = ls.shade(self.Z, cmap=cm.gist_earth, vert_exag=0.1, blend_mode='soft')
     
     self.ax.plot_surface(self.X, self.Y, self.Z, facecolors=rgb)
     
     self.setLabels()
     plt.show()
开发者ID:ldesousa,项目名称:hex-utils,代码行数:15,代码来源:surface.py

示例10: getTopoRGB

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
def getTopoRGB(topogrid):
    topotmp = topogrid.getData().copy()
    # make a masked array
    topotmp = np.ma.array(topotmp)
    topodat = np.ma.masked_where(np.isnan(topotmp), topotmp)
    cy = topogrid.geodict["ymin"] + (topogrid.geodict["ymax"] - topogrid.geodict["ymin"]) / 2.0
    # flag the regions where topography is less than 0 (we'll color this ocean later)
    i = np.where(topodat == SEA_LEVEL)

    # do shaded relief stuff
    # keys are latitude values
    # values are multiplication factor
    zdict = {
        0: 0.00000898,
        10: 0.00000912,
        20: 0.00000956,
        30: 0.00001036,
        40: 0.00001171,
        50: 0.00001395,
        60: 0.00001792,
        70: 0.00002619,
        80: 0.00005156,
    }
    # find the mean latitude of the map we're making, and use that to come up with a zfactor
    mlat = abs(int(round(cy / 10) * 10))
    zfactor = zdict[mlat]
    ls = LightSource(azdeg=AZDEFAULT, altdeg=ALTDEFAULT)

    # draw the ocean in light blue
    water_color = [0.47, 0.60, 0.81]
    palette1 = copy.deepcopy(cm.binary)

    # draw the light shaded-topography
    rgbdata = topodat * zfactor  # apply the latitude specific zfactor correction
    rgb = ls.shade(rgbdata, cmap=palette1)  # apply the light shading to our corrected topography

    # this is an rgb data set now, so masking the pixels won't work, but explicitly setting all of the
    # "bad" pixels to our water color will
    red = rgb[:, :, 0]
    green = rgb[:, :, 1]
    blue = rgb[:, :, 2]
    red[i] = water_color[0]
    green[i] = water_color[1]
    blue[i] = water_color[2]
    rgb[:, :, 0] = red
    rgb[:, :, 1] = green
    rgb[:, :, 2] = blue

    rgb = np.flipud(rgb)

    return (rgb, palette1)
开发者ID:kallstadt-usgs,项目名称:secondary,代码行数:53,代码来源:map.py

示例11: compare

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
def compare(z, cmap, ve=1):
    # Create subplots and hide ticks
    fig, axes = plt.subplots(ncols=2, nrows=2)
    for ax in axes.flat:
        ax.set(xticks=[], yticks=[])

    # Illuminate the scene from the northwest
    ls = LightSource(azdeg=315, altdeg=45)

    axes[0, 0].imshow(z, cmap=cmap)
    axes[0, 0].set(xlabel='Colormapped Data')

    axes[0, 1].imshow(ls.hillshade(z, vert_exag=ve), cmap='gray')
    axes[0, 1].set(xlabel='Illumination Intensity')

    rgb = ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='hsv')
    axes[1, 0].imshow(rgb)
    axes[1, 0].set(xlabel='Blend Mode: "hsv" (default)')

    rgb = ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='overlay')
    axes[1, 1].imshow(rgb)
    axes[1, 1].set(xlabel='Blend Mode: "overlay"')

    return fig
开发者ID:adnanb59,项目名称:matplotlib,代码行数:26,代码来源:shading_example.py

示例12: display_depth_matplotlib

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
def display_depth_matplotlib(z):
    """
    Same as above but using matplotlib instead.
    """
    from mpl_toolkits.mplot3d import Axes3D
    from matplotlib.colors import LightSource
    
    m, n = z.shape
    x, y = np.mgrid[0:m, 0:n]
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    ls = LightSource(azdeg=0, altdeg=65)
    greyvals = ls.shade(z, plt.cm.Greys)
    ax.plot_surface(x, y, z, rstride=1, cstride=1, linewidth=0, antialiased=False, facecolors=greyvals)
    plt.axis('off')
    plt.axis('equal')
    plt.show()
开发者ID:McC0dy,项目名称:PhotometricStereoVision,代码行数:19,代码来源:ps_utils.py

示例13: display_colorbar

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
def display_colorbar():
    """Display a correct numeric colorbar for a shaded plot."""
    y, x = np.mgrid[-4:2:200j, -4:2:200j]
    z = 10 * np.cos(x**2 + y**2)

    cmap = plt.cm.copper
    ls = LightSource(315, 45)
    rgb = ls.shade(z, cmap)

    fig, ax = plt.subplots()
    ax.imshow(rgb)

    # Use a proxy artist for the colorbar...
    im = ax.imshow(z, cmap=cmap)
    im.remove()
    fig.colorbar(im)

    ax.set_title('Using a colorbar with a shaded plot', size='x-large')
开发者ID:717524640,项目名称:matplotlib,代码行数:20,代码来源:advanced_hillshading.py

示例14: main3

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
def main3():
    ax = plt.axes(projection=ccrs.PlateCarree())

    elev, crs, extent = io_srtm.srtm_composite(-5, 52, 2, 2)

    elev = np.ma.masked_less_equal(elev, 0, copy=False)

    use_mpl_light_source = False
    
    if use_mpl_light_source:
        from matplotlib.colors import LightSource
    
        ls = LightSource(azdeg=90, altdeg=80,
                         hsv_min_val=0.6, hsv_min_sat=0.9,
                         hsv_max_val=0.8, hsv_max_sat=1,
                         )
    
        rgb = ls.shade(elev, plt.get_cmap('Greens', 3))
    else:
        import matplotlib.colors as mcolors
        rgb = set_shade(elev,
                        cmap=mcolors.ListedColormap([plt.get_cmap('Greens', 3)(0.5)])
                    )


    ax.imshow(rgb,
                extent=extent,
                transform=crs
                )

    x = np.linspace(extent[0], extent[1], elev.shape[0])
    y = np.linspace(extent[2], extent[3], elev.shape[1])
#
#    ax.contour(x, y, elev, 100,
#               linestyles='-',
#               colors='blue',
#               linewidths=0.3,
#               alpha=0.4,
#               transform=crs,
#               )

    plt.show()
开发者ID:bjlittle,项目名称:cartopy,代码行数:44,代码来源:srtm.py

示例15: mapwithtopo

# 需要导入模块: from matplotlib.colors import LightSource [as 别名]
# 或者: from matplotlib.colors.LightSource import shade [as 别名]
def mapwithtopo(p,ax=[],cutdepth=[],aspect=2.5,cmap=[],dlon=30,dlat=10,smooth=False):
    import popy,os
    from netCDF4 import Dataset
    from mpl_toolkits.basemap import shiftgrid
    from matplotlib.colors import LightSource
    import pylab as plt
    import numpy as np
    
    etopofn='/net/mazdata2/jinbo/mdata5-jinbo/obs/ETOPO/ETOPO1_Bed_g_gmt4.grd'
    etopo = Dataset(etopofn,'r').variables
    x,y,z=etopo['x'][1:],etopo['y'][1:],etopo['z'][1:,1:]
    dx,dy=5,5
    x=x.reshape(-1,dx).mean(axis=-1)
    y=y.reshape(-1,dx).mean(axis=-1)
    z=z.reshape(y.size,dx,x.size,dx).mean(axis=-1).mean(axis=1)
    if smooth:
        z=popy.utils.smooth2d(z,window_len=3)
    
    if cutdepth!=[]:
        z[z<cutdepth]=cutdepth
        
    if ax==[]:
        fig=plt.figure()
        ax=fig.add_subplot()
    if cmap==[]:
        cmap=plt.cm.Greys
        
    z,x = shiftgrid(p[0],z,x,start=True)
    lon,lat,z = popy.utils.subtractsubdomain(x,y,p,z)
    
    m = setmap(p=p,dlon=dlon,dlat=dlat)
    x, y = m(*np.meshgrid(lon, lat))
    ls = LightSource(azdeg=90, altdeg=45)
    rgb = ls.shade(z, cmap=cmap)
    m.imshow(rgb, aspect=aspect)
    
    plt.savefig('/tmp/tmp.png')
    os.popen('eog /tmp/tmp.png')
    return etopo
开发者ID:crocha700,项目名称:popy,代码行数:41,代码来源:map.py


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