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


Python colors.PowerNorm方法代码示例

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


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

示例1: ExploringNormalizations

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import PowerNorm [as 别名]
def ExploringNormalizations():
    import matplotlib.pyplot as plt
    import matplotlib.colors as mcolors
    import numpy as np
    from numpy.random import multivariate_normal

    data = np.vstack([
        multivariate_normal([10, 10], [[3, 2], [2, 3]], size=100000),
        multivariate_normal([30, 20], [[2, 3], [1, 3]], size=1000)
    ])

    gammas = [0.8, 0.5, 0.3]

    fig, axes = plt.subplots(nrows=2, ncols=2)

    axes[0, 0].set_title('Linear normalization')
    axes[0, 0].hist2d(data[:, 0], data[:, 1], bins=100)

    for ax, gamma in zip(axes.flat[1:], gammas):
        ax.set_title(r'Power law $(\gamma=%1.1f)$' % gamma)
        ax.hist2d(data[:, 0], data[:, 1],
                  bins=100, norm=mcolors.PowerNorm(gamma))

    fig.tight_layout()
    return fig 
开发者ID:PySimpleGUI,项目名称:PySimpleGUI,代码行数:27,代码来源:Demo_Matplotlib_Browser.py

示例2: test_PowerNorm

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import PowerNorm [as 别名]
def test_PowerNorm():
    a = np.array([0, 0.5, 1, 1.5], dtype=np.float)
    pnorm = mcolors.PowerNorm(1)
    norm = mcolors.Normalize()
    assert_array_almost_equal(norm(a), pnorm(a))

    a = np.array([-0.5, 0, 2, 4, 8], dtype=np.float)
    expected = [0, 0, 1/16, 1/4, 1]
    pnorm = mcolors.PowerNorm(2, vmin=0, vmax=8)
    assert_array_almost_equal(pnorm(a), expected)
    assert_equal(pnorm(a[0]), expected[0])
    assert_equal(pnorm(a[2]), expected[2])
    assert_array_almost_equal(a[1:], pnorm.inverse(pnorm(a))[1:])

    # Clip = True
    a = np.array([-0.5, 0, 1, 8, 16], dtype=np.float)
    expected = [0, 0, 0, 1, 1]
    pnorm = mcolors.PowerNorm(2, vmin=2, vmax=8, clip=True)
    assert_array_almost_equal(pnorm(a), expected)
    assert_equal(pnorm(a[0]), expected[0])
    assert_equal(pnorm(a[-1]), expected[-1])

    # Clip = True at call time
    a = np.array([-0.5, 0, 1, 8, 16], dtype=np.float)
    expected = [0, 0, 0, 1, 1]
    pnorm = mcolors.PowerNorm(2, vmin=2, vmax=8, clip=False)
    assert_array_almost_equal(pnorm(a, clip=True), expected)
    assert_equal(pnorm(a[0], clip=True), expected[0])
    assert_equal(pnorm(a[-1], clip=True), expected[-1]) 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:31,代码来源:test_colors.py

示例3: test_PowerNorm

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import PowerNorm [as 别名]
def test_PowerNorm():
    a = np.array([0, 0.5, 1, 1.5], dtype=float)
    pnorm = mcolors.PowerNorm(1)
    norm = mcolors.Normalize()
    assert_array_almost_equal(norm(a), pnorm(a))

    a = np.array([-0.5, 0, 2, 4, 8], dtype=float)
    expected = [0, 0, 1/16, 1/4, 1]
    pnorm = mcolors.PowerNorm(2, vmin=0, vmax=8)
    assert_array_almost_equal(pnorm(a), expected)
    assert pnorm(a[0]) == expected[0]
    assert pnorm(a[2]) == expected[2]
    assert_array_almost_equal(a[1:], pnorm.inverse(pnorm(a))[1:])

    # Clip = True
    a = np.array([-0.5, 0, 1, 8, 16], dtype=float)
    expected = [0, 0, 0, 1, 1]
    pnorm = mcolors.PowerNorm(2, vmin=2, vmax=8, clip=True)
    assert_array_almost_equal(pnorm(a), expected)
    assert pnorm(a[0]) == expected[0]
    assert pnorm(a[-1]) == expected[-1]

    # Clip = True at call time
    a = np.array([-0.5, 0, 1, 8, 16], dtype=float)
    expected = [0, 0, 0, 1, 1]
    pnorm = mcolors.PowerNorm(2, vmin=2, vmax=8, clip=False)
    assert_array_almost_equal(pnorm(a, clip=True), expected)
    assert pnorm(a[0], clip=True) == expected[0]
    assert pnorm(a[-1], clip=True) == expected[-1] 
开发者ID:holzschu,项目名称:python3_ios,代码行数:31,代码来源:test_colors.py

示例4: test_PowerNorm_translation_invariance

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import PowerNorm [as 别名]
def test_PowerNorm_translation_invariance():
    a = np.array([0, 1/2, 1], dtype=float)
    expected = [0, 1/8, 1]
    pnorm = mcolors.PowerNorm(vmin=0, vmax=1, gamma=3)
    assert_array_almost_equal(pnorm(a), expected)
    pnorm = mcolors.PowerNorm(vmin=-2, vmax=-1, gamma=3)
    assert_array_almost_equal(pnorm(a - 2), expected) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:9,代码来源:test_colors.py

示例5: test_ndarray_subclass_norm

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import PowerNorm [as 别名]
def test_ndarray_subclass_norm(recwarn):
    # Emulate an ndarray subclass that handles units
    # which objects when adding or subtracting with other
    # arrays. See #6622 and #8696
    class MyArray(np.ndarray):
        def __isub__(self, other):
            raise RuntimeError

        def __add__(self, other):
            raise RuntimeError

    data = np.arange(-10, 10, 1, dtype=float)
    data.shape = (10, 2)
    mydata = data.view(MyArray)

    for norm in [mcolors.Normalize(), mcolors.LogNorm(),
                 mcolors.SymLogNorm(3, vmax=5, linscale=1),
                 mcolors.Normalize(vmin=mydata.min(), vmax=mydata.max()),
                 mcolors.SymLogNorm(3, vmin=mydata.min(), vmax=mydata.max()),
                 mcolors.PowerNorm(1)]:
        assert_array_equal(norm(mydata), norm(data))
        fig, ax = plt.subplots()
        ax.imshow(mydata, norm=norm)
        fig.canvas.draw()
        assert len(recwarn) == 0
        recwarn.clear() 
开发者ID:holzschu,项目名称:python3_ios,代码行数:28,代码来源:test_colors.py

示例6: test_colorbar_powernorm_extension

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import PowerNorm [as 别名]
def test_colorbar_powernorm_extension():
    # Test that colorbar with powernorm is extended correctly
    f, ax = plt.subplots()
    cb = ColorbarBase(ax, norm=PowerNorm(gamma=0.5, vmin=0.0, vmax=1.0),
                      orientation='vertical', extend='both')
    assert cb._values[0] >= 0.0 
开发者ID:holzschu,项目名称:python3_ios,代码行数:8,代码来源:test_colorbar.py

示例7: __init__

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import PowerNorm [as 别名]
def __init__(self, fig, gs, ray_list,
                 user_scale_value=0.1, scale_type='fit',
                 yaxis_ticks_position='left', dsp_typ='hist2d',
                 **kwargs):
        self.fig = fig
        self.fig.subplots.append(self)

        self.gs = gs
        self.ray_list = ray_list
        self.dsp_typ = dsp_typ

        if 'title' in kwargs:
            self.title = kwargs.pop('title', None)

        if 'norm' in kwargs:
            self.norm = kwargs.pop('norm', None)
        else:
            gamma = kwargs.pop('gamma', 0.5)
            vmax = kwargs.get('vmax') if 'vmax' in kwargs else None
            self.norm = PowerNorm(gamma, vmin=0., vmax=vmax)

        self.plot_kwargs = kwargs

        self.user_scale_value = user_scale_value
        self.scale_type = scale_type
        self.yaxis_ticks_position = yaxis_ticks_position

        self.update_data() 
开发者ID:mjhoptics,项目名称:ray-optics,代码行数:30,代码来源:analysisfigure.py

示例8: plot

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import PowerNorm [as 别名]
def plot(self):
        '''Replot the colorbar.'''
        if self.cmap is None:
            return

        self.ax.cla()
        self.cax.cla()
        cmap = self.cmap
        if 'norm' not in cmap or cmap['norm'] is None:
            self.norm_type.setCurrentIndex(0)
        else:
            norm_name = cmap['norm'].__class__.__name__
            if norm_name == 'Normalize':
                self.norm_type.setCurrentIndex(1)
            elif norm_name == 'LogNorm':
                self.norm_type.setCurrentIndex(2)
            elif norm_name == 'SymLogNorm':
                self.norm_type.setCurrentIndex(3)
            elif norm_name == 'PowerNorm':
                self.norm_type.setCurrentIndex(4)
            elif norm_name == 'BoundaryNorm':
                self.norm_type.setCurrentIndex(5)

        if cmap is not None:
            if 'norm' in cmap:
                norm = cmap['norm']
            else:
                norm = None
            im = self.ax.imshow(gradient, aspect='auto', cmap=cmap['cmap'],
                                vmin=cmap['vmin'], vmax=cmap['vmax'],
                                norm=norm)
            plt.colorbar(im, cax=self.cax)

        self.canvas.draw() 
开发者ID:nguy,项目名称:artview,代码行数:36,代码来源:cmap.py

示例9: update_colormap

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import PowerNorm [as 别名]
def update_colormap(self):
        '''Get colormap from GUI.'''
        self.cmap['lock'] = self.lock_box.isChecked()
        idx = self.norm_type.currentIndex()

        self.cmap['vmin'] = float(self.ent_vmin.text())
        self.cmap['vmax'] = float(self.ent_vmax.text())

        if idx == 0:
            self.cmap['norm'] = None
        elif idx == 1:
            self.cmap['norm'] = colors.Normalize(vmin=self.cmap['vmin'],
                                                 vmax=self.cmap['vmax'])
        elif idx == 2:
            self.cmap['norm'] = colors.LogNorm(vmin=self.cmap['vmin'],
                                               vmax=self.cmap['vmax'])
        elif idx == 3:
            self.cmap['norm'] = colors.SymLogNorm(
                linthresh=float(self.ent_linthresh.text()),
                linscale=float(self.ent_linscale.text()),
                vmin=self.cmap['vmin'],
                vmax=self.cmap['vmax'])
        elif idx == 4:
            self.cmap['norm'] = colors.PowerNorm(
                gamma=float(self.ent_gamma.text()),
                vmin=self.cmap['vmin'],
                vmax=self.cmap['vmax'])
        elif idx == 5:
            bounds = self.get_bounds()
            self.cmap['norm'] = colors.BoundaryNorm(bounds,
                                                    ncolors=256)
        self.plot() 
开发者ID:nguy,项目名称:artview,代码行数:34,代码来源:cmap.py

示例10: test_ndarray_subclass_norm

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import PowerNorm [as 别名]
def test_ndarray_subclass_norm(recwarn):
    # Emulate an ndarray subclass that handles units
    # which objects when adding or subtracting with other
    # arrays. See #6622 and #8696
    class MyArray(np.ndarray):
        def __isub__(self, other):
            raise RuntimeError

        def __add__(self, other):
            raise RuntimeError

    data = np.arange(-10, 10, 1, dtype=float)
    data.shape = (10, 2)
    mydata = data.view(MyArray)

    for norm in [mcolors.Normalize(), mcolors.LogNorm(),
                 mcolors.SymLogNorm(3, vmax=5, linscale=1),
                 mcolors.Normalize(vmin=mydata.min(), vmax=mydata.max()),
                 mcolors.SymLogNorm(3, vmin=mydata.min(), vmax=mydata.max()),
                 mcolors.PowerNorm(1)]:
        assert_array_equal(norm(mydata), norm(data))
        fig, ax = plt.subplots()
        ax.imshow(mydata, norm=norm)
        fig.canvas.draw()
        if isinstance(norm, mcolors.PowerNorm):
            assert len(recwarn) == 1
            warn = recwarn.pop(UserWarning)
            assert ('Power-law scaling on negative values is ill-defined'
                    in str(warn.message))
        else:
            assert len(recwarn) == 0
        recwarn.clear() 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:34,代码来源:test_colors.py

示例11: make_drape_plot

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import PowerNorm [as 别名]
def make_drape_plot(self):
        """Creates a matplotlib Axes object with the drape map."""
        
        # but what if fig XOR ax is None??
#        if fig is None and ax is None:
#            self.fig, self.ax = plt.subplots()
#        else:
#            self.fig=fig, self.ax=ax

        
        
        # Plot the background
        self.im_background = self.ax.imshow(self.Background.Hillshade,
                                 self.Background.colourmap,
                                 extent=self.Background.extents,
                                 interpolation="nearest", vmax=450)
        self._num_drapes += 1
        self._drape_list.append(self.im_background)
        
        if self._show_background_colourbar:
            # Plot the background image colour bar
            self._generic_colourbar_plotter(self.im_background, "Elevation (m)")
        
        # Plot the drape (overlay data) on top.
        # Should be separate function really...
        if not self.HideDrape:
            self.im = self.ax.imshow(self.Drape._RasterArray,
                                     self._drape_colourmap,
                                     extent=self.Drape.extents,
                                     interpolation="nearest",
                                     vmin=self._vmin, vmax=self._vmax,
                                     norm=self._colourbar_normalisation,
                                     alpha=self._drape_alpha
                                     )
                                     #norm=_mcolors.PowerNorm(gamma=0.2))
            
            self._drape_list.append(self.im)
            self._num_drapes += 1
            
            
            
            # Add the colourbar for the drape
            self._generic_colourbar_plotter(self.im, self._colourbar_label)
        
        # Add a title
        self._set_subplot_autolabel()
        self._set_axis_labels(self._xaxis_label, self._yaxis_label)
        
        
        #return self.fig, self.ax 
开发者ID:LSDtopotools,项目名称:LSDMappingTools,代码行数:52,代码来源:drapeplot.py


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