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


Python colors.LightSource方法代码示例

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


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

示例1: compare

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

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

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

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

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

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

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

示例2: display_colorbar

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import LightSource [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, interpolation='bilinear')

    # 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:holzschu,项目名称:python3_ios,代码行数:20,代码来源:advanced_hillshading.py

示例3: avoid_outliers

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import LightSource [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, interpolation='bilinear')
    ax1.set_title('Full range of data')

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

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

示例4: test_light_source_topo_surface

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import LightSource [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:jgagneastro,项目名称:coffeegrindsize,代码行数:24,代码来源:test_colors.py

示例5: ThrShow

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import LightSource [as 别名]
def ThrShow(self,data):        
        font1 = {'family' : 'STXihei',
         'weight' : 'normal',
         'size'   : 50,
         }
        fig, ax = plt.subplots(subplot_kw=dict(projection='3d'),figsize=(50,20))
        ls = LightSource(data.shape[0], data.shape[1])
        rgb = ls.shade(data, cmap=cm.gist_earth, vert_exag=0.1, blend_mode='soft')
        x=np.array([list(range(data.shape[0]))]*data.shape[1])
        print(x.shape,x.T.shape,data.shape)
        surf = ax.plot_surface(x, x.T, data, rstride=1, cstride=1, facecolors=rgb,linewidth=0, antialiased=False, shade=False,alpha=0.3)
        fig.colorbar(surf,shrink=0.5,aspect=5)
        cset = ax.contour(x, x.T, data, zdir='z', offset=37, cmap=cm.coolwarm)
        cset = ax.contour(x, x.T, data, zdir='x', offset=-30, cmap=cm.coolwarm)
        cset = ax.contour(x, x.T, data, zdir='y', offset=-30, cmap=cm.coolwarm)
        plt.show() 
开发者ID:richieBao,项目名称:python-urbanPlanning,代码行数:18,代码来源:LST.py

示例6: hillshaded

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import LightSource [as 别名]
def hillshaded(a, land_mask=None, angle=270):
  if land_mask is None: land_mask = np.ones_like(a)
  ls = LightSource(azdeg=angle, altdeg=30)
  land = ls.shade(a, cmap=_TERRAIN_CMAP, vert_exag=10.0,
                  blend_mode='overlay')[:, :, :3]
  water = np.tile((0.25, 0.35, 0.55), a.shape + (1,))
  return lerp(water, land, land_mask[:, :, np.newaxis])


# Linear interpolation of `x` to `y` with respect to `a` 
开发者ID:dandrino,项目名称:terrain-erosion-3-ways,代码行数:12,代码来源:util.py

示例7: _shade_colors_lightsource

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import LightSource [as 别名]
def _shade_colors_lightsource(self, data, cmap, lightsource):
        if lightsource is None:
            lightsource = LightSource(azdeg=135, altdeg=55)
        return lightsource.shade(data, cmap) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:6,代码来源:axes3d.py

示例8: test_light_source_shading_color_range

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import LightSource [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:miloharper,项目名称:neural-network-animation,代码行数:28,代码来源:test_colors.py

示例9: __init__

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import LightSource [as 别名]
def __init__(self, sigma, fraction=0.5):
        self.gauss_filter = GaussianFilter(sigma, alpha=1)
        self.light_source = LightSource()
        self.fraction = fraction 
开发者ID:holzschu,项目名称:python3_ios,代码行数:6,代码来源:demo_agg_filter.py

示例10: shade_other_data

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import LightSource [as 别名]
def shade_other_data():
    """Demonstrates displaying different variables through shade and color."""
    y, x = np.mgrid[-4:2:200j, -4:2:200j]
    z1 = np.sin(x**2)  # Data to hillshade
    z2 = np.cos(x**2 + y**2)  # Data to color

    norm = Normalize(z2.min(), z2.max())
    cmap = plt.cm.RdBu

    ls = LightSource(315, 45)
    rgb = ls.shade_rgb(cmap(norm(z2)), z1)

    fig, ax = plt.subplots()
    ax.imshow(rgb, interpolation='bilinear')
    ax.set_title('Shade by one variable, color by another', size='x-large') 
开发者ID:holzschu,项目名称:python3_ios,代码行数:17,代码来源:advanced_hillshading.py

示例11: test_light_source_hillshading

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import LightSource [as 别名]
def test_light_source_hillshading():
    """Compare the current hillshading method against one that should be
    mathematically equivalent. Illuminates a cone from a range of angles."""

    def alternative_hillshade(azimuth, elev, z):
        illum = _sph2cart(*_azimuth2math(azimuth, elev))
        illum = np.array(illum)

        dy, dx = np.gradient(-z)
        dy = -dy
        dz = np.ones_like(dy)
        normals = np.dstack([dx, dy, dz])
        normals /= np.linalg.norm(normals, axis=2)[..., None]

        intensity = np.tensordot(normals, illum, axes=(2, 0))
        intensity -= intensity.min()
        intensity /= intensity.ptp()
        return intensity

    y, x = np.mgrid[5:0:-1, :5]
    z = -np.hypot(x - x.mean(), y - y.mean())

    for az, elev in itertools.product(range(0, 390, 30), range(0, 105, 15)):
        ls = mcolors.LightSource(az, elev)
        h1 = ls.hillshade(z)
        h2 = alternative_hillshade(az, elev, z)
        assert_array_almost_equal(h1, h2) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:29,代码来源:test_colors.py

示例12: test_light_source_planar_hillshading

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import LightSource [as 别名]
def test_light_source_planar_hillshading():
    """Ensure that the illumination intensity is correct for planar
    surfaces."""

    def plane(azimuth, elevation, x, y):
        """Create a plane whose normal vector is at the given azimuth and
        elevation."""
        theta, phi = _azimuth2math(azimuth, elevation)
        a, b, c = _sph2cart(theta, phi)
        z = -(a*x + b*y) / c
        return z

    def angled_plane(azimuth, elevation, angle, x, y):
        """Create a plane whose normal vector is at an angle from the given
        azimuth and elevation."""
        elevation = elevation + angle
        if elevation > 90:
            azimuth = (azimuth + 180) % 360
            elevation = (90 - elevation) % 90
        return plane(azimuth, elevation, x, y)

    y, x = np.mgrid[5:0:-1, :5]
    for az, elev in itertools.product(range(0, 390, 30), range(0, 105, 15)):
        ls = mcolors.LightSource(az, elev)

        # Make a plane at a range of angles to the illumination
        for angle in range(0, 105, 15):
            z = angled_plane(az, elev, angle, x, y)
            h = ls.hillshade(z)
            assert_array_almost_equal(h, np.cos(np.radians(angle))) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:32,代码来源:test_colors.py

示例13: _shade_colors

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import LightSource [as 别名]
def _shade_colors(color, normals, lightsource=None):
    """
    Shade *color* using normal vectors given by *normals*.
    *color* can also be an array of the same length as *normals*.
    """
    if lightsource is None:
        # chosen for backwards-compatibility
        lightsource = LightSource(azdeg=225, altdeg=19.4712)

    def mod(v):
        return np.sqrt(v[0] ** 2 + v[1] ** 2 + v[2] ** 2)

    shade = np.array([np.dot(n / mod(n), lightsource.direction)
                      if mod(n) else np.nan for n in normals])
    mask = ~np.isnan(shade)

    if mask.any():
        norm = Normalize(min(shade[mask]), max(shade[mask]))
        shade[~mask] = min(shade[mask])
        color = mcolors.to_rgba_array(color)
        # shape of color should be (M, 4) (where M is number of faces)
        # shape of shade should be (M,)
        # colors should have final shape of (M, 4)
        alpha = color[:, 3]
        colors = (0.5 + norm(shade)[:, np.newaxis] * 0.5) * color
        colors[:, 3] = alpha
    else:
        colors = np.asanyarray(color).copy()

    return colors 
开发者ID:Qiskit,项目名称:qiskit-terra,代码行数:32,代码来源:state_visualization.py

示例14: createLatLonTimeAverageMap3d

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import LightSource [as 别名]
def createLatLonTimeAverageMap3d(res, meta, startTime=None, endTime=None):
    latSeries = [m[0]['lat'] for m in res][::-1]
    lonSeries = [m['lon'] for m in res[0]]
    data = np.zeros((len(latSeries), len(lonSeries)))
    for t in range(0, len(latSeries)):
        latSet = res[t]
        for l in range(0, len(lonSeries)):
            data[len(latSeries) - t - 1][l] = latSet[l]['avg']
    data[data == 0.0] = np.nan

    x, y = np.meshgrid(latSeries, lonSeries)
    z = data

    region = np.s_[0:178, 0:178]
    x, y, z = x[region], y[region], z[region]

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

    ls = LightSource(270, 45)
    masked_array = np.ma.array(z, mask=np.isnan(z))
    rgb = ls.shade(masked_array, cmap=cm.gist_earth)  # , vert_exag=0.1, blend_mode='soft')
    surf = ax.plot_surface(x, y, masked_array, rstride=1, cstride=1, facecolors=rgb,
                           linewidth=0, antialiased=False, shade=False)
    sio = StringIO()
    plt.savefig(sio, format='png')
    return sio.getvalue() 
开发者ID:apache,项目名称:incubator-sdap-nexus,代码行数:28,代码来源:plotting.py

示例15: createHoffmueller

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import LightSource [as 别名]
def createHoffmueller(data, coordSeries, timeSeries, coordName, title, interpolate='nearest'):
    cmap = cm.coolwarm
    # ls = LightSource(315, 45)
    # rgb = ls.shade(data, cmap)

    fig, ax = plt.subplots()
    fig.set_size_inches(11.0, 8.5)
    cax = ax.imshow(data, interpolation=interpolate, cmap=cmap)

    def yFormatter(y, pos):
        if y < len(coordSeries):
            return "%s $^\circ$" % (int(coordSeries[int(y)] * 100.0) / 100.)
        else:
            return ""

    def xFormatter(x, pos):
        if x < len(timeSeries):
            return timeSeries[int(x)].strftime('%b %Y')
        else:
            return ""

    ax.xaxis.set_major_formatter(FuncFormatter(xFormatter))
    ax.yaxis.set_major_formatter(FuncFormatter(yFormatter))

    ax.set_title(title)
    ax.set_ylabel(coordName)
    ax.set_xlabel('Date')

    fig.colorbar(cax)
    fig.autofmt_xdate()

    labels = ['point {0}'.format(i + 1) for i in range(len(data))]
    # plugins.connect(fig, plugins.MousePosition(fontsize=14))
    tooltip = mpld3.plugins.PointLabelTooltip(cax, labels=labels)
    mpld3.plugins.connect(fig, tooltip)
    mpld3.show()
    # sio = StringIO()
    # plt.savefig(sio, format='png')
    # return sio.getvalue() 
开发者ID:apache,项目名称:incubator-sdap-nexus,代码行数:41,代码来源:plotting.py


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