當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。