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


Python colors.BoundaryNorm方法代码示例

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


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

示例1: _get_cmap_norms

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def _get_cmap_norms():
    """
    Define a colormap and appropriate norms for each of the four
    possible settings of the extend keyword.

    Helper function for _colorbar_extension_shape and
    colorbar_extension_length.
    """
    # Create a color map and specify the levels it represents.
    cmap = get_cmap("RdBu", lut=5)
    clevs = [-5., -2.5, -.5, .5, 1.5, 3.5]
    # Define norms for the color maps.
    norms = dict()
    norms['neither'] = BoundaryNorm(clevs, len(clevs) - 1)
    norms['min'] = BoundaryNorm([-10] + clevs[1:], len(clevs) - 1)
    norms['max'] = BoundaryNorm(clevs[:-1] + [10], len(clevs) - 1)
    norms['both'] = BoundaryNorm([-10] + clevs[1:-1] + [10], len(clevs) - 1)
    return cmap, norms 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:20,代码来源:test_colorbar.py

示例2: _select_locator

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def _select_locator(self, formatter):
        '''
        select a suitable locator
        '''
        if self.boundaries is None:
            if isinstance(self.norm, colors.NoNorm):
                nv = len(self._values)
                base = 1 + int(nv/10)
                locator = ticker.IndexLocator(base=base, offset=0)
            elif isinstance(self.norm, colors.BoundaryNorm):
                b = self.norm.boundaries
                locator = ticker.FixedLocator(b, nbins=10)
            elif isinstance(self.norm, colors.LogNorm):
                locator = ticker.LogLocator()
            else:
                locator = ticker.MaxNLocator(nbins=5)
        else:
            b = self._boundaries[self._inside]
            locator = ticker.FixedLocator(b) #, nbins=10)

        self.cbar_axis.set_major_locator(locator) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:23,代码来源:colorbar.py

示例3: plot_colormap

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def plot_colormap(cmap, continuous=True, discrete=True, ndisc=9):
    """Make a figure displaying the color map in continuous and/or discrete form
    """
    nplots = int(continuous) + int(discrete)
    fig, axx = plt.subplots(figsize=(6,.5*nplots), nrows=nplots, frameon=False)
    axx = np.asarray(axx)
    i=0
    if continuous:
        norm = mcolors.Normalize(vmin=0, vmax=1)
        ColorbarBase(axx.flat[i], cmap=cmap, norm=norm, orientation='horizontal') ; i+=1
    if discrete:
        colors = cmap(np.linspace(0, 1, ndisc))
        cmap_d = mcolors.ListedColormap(colors, name=cmap.name)
        norm = mcolors.BoundaryNorm(np.linspace(0, 1, ndisc+1), len(colors))
        ColorbarBase(axx.flat[i], cmap=cmap_d, norm=norm, orientation='horizontal')
    for ax in axx.flat:
        ax.set_axis_off()
    fig.text(0.95, 0.5, cmap.name, va='center', ha='left', fontsize=12) 
开发者ID:j08lue,项目名称:pycpt,代码行数:20,代码来源:display.py

示例4: plot_slic

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def plot_slic(array, clusters, K, S, output_figure = ''):
    fig = plt.figure(figsize=(8, 6))
    # create colormap based on cluster RGB centers
    slic_colormap = []
    for c in clusters:
        slic_colormap.append((c[0], c[1], c[2], 1.0))
    slic_listed_colormap = ListedColormap(slic_colormap)
    slic_norm = BoundaryNorm(range(K), K)
    plt.imshow(array, norm=slic_norm, cmap=slic_listed_colormap)
    # adjust image
    (rows, columns) = array.shape
    plt.xlim([0 - S, columns + S])
    plt.ylim([0 - S, rows + S])

    if output_figure != '':
        plt.savefig(output_figure, format='png', dpi=1000)
    else:
        plt.show()

# open dataset 
开发者ID:tkorting,项目名称:youtube,代码行数:22,代码来源:main.py

示例5: show

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def show(self, image, label_1s, label_2s, label_3s, label, label_at):
        import matplotlib.pyplot as plt
        from matplotlib import colors
        # make a color map of fixed colors
        cmap = colors.ListedColormap([(0,0,0), (0.5,0,0), (0,0.5,0), (0.5,0.5,0), (0,0,0.5), (0.5,0,0.5), (0,0.5,0.5)])
        bounds=[0,1,2,3,4,5,6,7]
        norm = colors.BoundaryNorm(bounds, cmap.N)

        fig, axes = plt.subplots(2,3)
        (ax1, ax2, ax3), (ax4, ax5, ax6) = axes
        ax1.set_title('image'); ax1.imshow(image)
        ax3.set_title('label'); ax2.imshow(label, cmap=cmap, norm=norm)
        ax3.set_title('label 1s'); ax3.imshow(label_1s, cmap=cmap, norm=norm)
        ax4.set_title('label 2s'); ax4.imshow(label_2s, cmap=cmap, norm=norm)
        ax5.set_title('label 3s'); ax5.imshow(label_3s, cmap=cmap, norm=norm)
        ax6.set_title('label at'); ax6.imshow(label_at, cmap=cmap, norm=norm)
        plt.show() 
开发者ID:speedinghzl,项目名称:Scale-Adaptive-Network,代码行数:19,代码来源:instance_attention.py

示例6: _select_locator

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def _select_locator(self, formatter):
        '''
        select a suitable locator
        '''
        if self.boundaries is None:
            if isinstance(self.norm, colors.NoNorm):
                nv = len(self._values)
                base = 1 + int(nv/10)
                locator = ticker.IndexLocator(base=base, offset=0)
            elif isinstance(self.norm, colors.BoundaryNorm):
                b = self.norm.boundaries
                locator = ticker.FixedLocator(b, nbins=10)
            elif isinstance(self.norm, colors.LogNorm):
                locator = ticker.LogLocator()
            else:
                locator = ticker.MaxNLocator(nbins=5)
        else:
            b = self._boundaries[self._inside]
            locator = ticker.FixedLocator(b)

        self.cbar_axis.set_major_locator(locator) 
开发者ID:boris-kz,项目名称:CogAlg,代码行数:23,代码来源:colorbar.py

示例7: __init__

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def __init__(self, env_name, n_channels):
        self.n_channels = n_channels

        # The seaborn color_palette cubhelix is used to assign visually distinct colors to each channel for the env
        self.cmap = sns.color_palette("cubehelix", self.n_channels)
        self.cmap.insert(0, (0, 0, 0))
        self.cmap = colors.ListedColormap(self.cmap)
        bounds = [i for i in range(self.n_channels + 2)]
        self.norm = colors.BoundaryNorm(bounds, self.n_channels + 1)

        self.root = Tk.Tk()
        self.root.title(env_name)
        self.root.config(background='white')

        self.root.attributes("-topmost", True)
        if platform() == 'Darwin':  # How Mac OS X is identified by Python
            system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python" to true' ''')
        self.root.focus_force()

        self.text_message = Tk.StringVar()
        self.label = Tk.Label(self.root, textvariable=self.text_message)

        self.fig = Figure()
        self.ax = self.fig.add_subplot(111)
        self.canvas = FigureCanvasTkAgg(self.fig, master=self.root)
        self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
        self.key_press_handler = self.canvas.mpl_connect('key_press_event', self.on_key_event)
        self.key_release_handler = self.canvas.mpl_connect('key_press_event', lambda x: None)

    # Set the message for the label on screen 
开发者ID:kenjyoung,项目名称:MinAtar,代码行数:32,代码来源:gui.py

示例8: _proportional_y

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def _proportional_y(self):
        '''
        Return colorbar data coordinates for the boundaries of
        a proportional colorbar.
        '''
        if isinstance(self.norm, colors.BoundaryNorm):
            y = (self._boundaries - self._boundaries[0])
            y = y / (self._boundaries[-1] - self._boundaries[0])
        else:
            y = self.norm(self._boundaries.copy())
        if self.extend == 'min':
            # Exclude leftmost interval of y.
            clen = y[-1] - y[1]
            automin = (y[2] - y[1]) / clen
            automax = (y[-1] - y[-2]) / clen
        elif self.extend == 'max':
            # Exclude rightmost interval in y.
            clen = y[-2] - y[0]
            automin = (y[1] - y[0]) / clen
            automax = (y[-2] - y[-3]) / clen
        else:
            # Exclude leftmost and rightmost intervals in y.
            clen = y[-2] - y[1]
            automin = (y[2] - y[1]) / clen
            automax = (y[-2] - y[-3]) / clen
        extendlength = self._get_extension_lengths(self.extendfrac,
                                                   automin, automax,
                                                   default=0.05)
        if self.extend in ('both', 'min'):
            y[0] = 0. - extendlength[0]
        if self.extend in ('both', 'max'):
            y[-1] = 1. + extendlength[1]
        yi = y[self._inside]
        norm = colors.Normalize(yi[0], yi[-1])
        y[self._inside] = norm(yi)
        return y 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:38,代码来源:colorbar.py

示例9: _locate

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def _locate(self, x):
        '''
        Given a set of color data values, return their
        corresponding colorbar data coordinates.
        '''
        if isinstance(self.norm, (colors.NoNorm, colors.BoundaryNorm)):
            b = self._boundaries
            xn = x
        else:
            # Do calculations using normalized coordinates so
            # as to make the interpolation more accurate.
            b = self.norm(self._boundaries, clip=False).filled()
            xn = self.norm(x, clip=False).filled()
        # The rest is linear interpolation with extrapolation at ends.
        y = self._y
        N = len(b)
        ii = np.searchsorted(b, xn)
        i0 = ii - 1
        itop = (ii == N)
        ibot = (ii == 0)
        i0[itop] -= 1
        ii[itop] -= 1
        i0[ibot] += 1
        ii[ibot] += 1

        #db = b[ii] - b[i0]
        db = np.take(b, ii) - np.take(b, i0)
        #dy = y[ii] - y[i0]
        dy = np.take(y, ii) - np.take(y, i0)
        z = np.take(y, i0) + (xn - np.take(b, i0)) * dy / db

        return z 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:34,代码来源:colorbar.py

示例10: _proportional_y

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def _proportional_y(self):
        '''
        Return colorbar data coordinates for the boundaries of
        a proportional colorbar.
        '''
        if isinstance(self.norm, colors.BoundaryNorm):
            y = (self._boundaries - self._boundaries[0])
            y = y / (self._boundaries[-1] - self._boundaries[0])
        else:
            y = self.norm(self._boundaries.copy())
            y = np.ma.filled(y, np.nan)
        if self.extend == 'min':
            # Exclude leftmost interval of y.
            clen = y[-1] - y[1]
            automin = (y[2] - y[1]) / clen
            automax = (y[-1] - y[-2]) / clen
        elif self.extend == 'max':
            # Exclude rightmost interval in y.
            clen = y[-2] - y[0]
            automin = (y[1] - y[0]) / clen
            automax = (y[-2] - y[-3]) / clen
        elif self.extend == 'both':
            # Exclude leftmost and rightmost intervals in y.
            clen = y[-2] - y[1]
            automin = (y[2] - y[1]) / clen
            automax = (y[-2] - y[-3]) / clen
        if self.extend in ('both', 'min', 'max'):
            extendlength = self._get_extension_lengths(self.extendfrac,
                                                       automin, automax,
                                                       default=0.05)
        if self.extend in ('both', 'min'):
            y[0] = 0. - extendlength[0]
        if self.extend in ('both', 'max'):
            y[-1] = 1. + extendlength[1]
        yi = y[self._inside]
        norm = colors.Normalize(yi[0], yi[-1])
        y[self._inside] = np.ma.filled(norm(yi), np.nan)
        return y 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:40,代码来源:colorbar.py

示例11: _locate

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def _locate(self, x):
        '''
        Given a set of color data values, return their
        corresponding colorbar data coordinates.
        '''
        if isinstance(self.norm, (colors.NoNorm, colors.BoundaryNorm)):
            b = self._boundaries
            xn = x
        else:
            # Do calculations using normalized coordinates so
            # as to make the interpolation more accurate.
            b = self.norm(self._boundaries, clip=False).filled()
            xn = self.norm(x, clip=False).filled()

        bunique = b
        yunique = self._y
        # trim extra b values at beginning and end if they are
        # not unique.  These are here for extended colorbars, and are not
        # wanted for the interpolation.
        if b[0] == b[1]:
            bunique = bunique[1:]
            yunique = yunique[1:]
        if b[-1] == b[-2]:
            bunique = bunique[:-1]
            yunique = yunique[:-1]

        z = np.interp(xn, bunique, yunique)
        return z 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:30,代码来源:colorbar.py

示例12: draw_matrix_user_ranking

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def draw_matrix_user_ranking(df_stat, higher_better=False, fig=None, cmap='tab20'):
    """ show matrix as image, sorted per column and unique colour per user

    :param DF df_stat: table where index are users and columns are scoring
    :param bool higher_better: ranking such that larger value is better
    :param fig: optional figure
    :param str cmap: color map
    :return Figure:

    >>> import pandas as pd
    >>> df = pd.DataFrame(np.random.random((5, 3)), columns=list('abc'))
    >>> draw_matrix_user_ranking(df)  # doctest: +ELLIPSIS
    <...>
    """
    ranking = compute_matrix_user_ranking(df_stat, higher_better)

    if fig is None:
        fig, _ = plt.subplots(figsize=np.array(df_stat.values.shape[::-1]) * 0.35)
    ax = fig.gca()
    arange = np.linspace(-0.5, len(df_stat) - 0.5, len(df_stat) + 1)
    norm = plt_colors.BoundaryNorm(arange, len(df_stat))
    fmt = plt_ticker.FuncFormatter(lambda x, pos: df_stat.index[x])

    draw_heatmap(ranking, np.arange(1, len(df_stat) + 1), df_stat.columns, ax=ax,
                 cmap=plt.get_cmap(cmap, len(df_stat)), norm=norm,
                 cbar_kw=dict(ticks=range(len(df_stat)), format=fmt),
                 cbar_label='Methods')
    ax.set_ylabel('Ranking')

    fig.tight_layout()
    return fig 
开发者ID:Borda,项目名称:BIRL,代码行数:33,代码来源:drawing.py

示例13: _plot_color_cycle

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def _plot_color_cycle(clists: Mapping[str, Sequence[str]]):
    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.colors import ListedColormap, BoundaryNorm

    fig, axes = plt.subplots(nrows=len(clists))  # type: plt.Figure, plt.Axes
    fig.subplots_adjust(top=.95, bottom=.01, left=.3, right=.99)
    axes[0].set_title('Color Maps/Cycles', fontsize=14)

    for ax, (name, clist) in zip(axes, clists.items()):
        n = len(clist)
        ax.imshow(
            np.arange(n)[None, :].repeat(2, 0),
            aspect='auto',
            cmap=ListedColormap(clist),
            norm=BoundaryNorm(np.arange(n+1)-.5, n),
        )
        pos = list(ax.get_position().bounds)
        x_text = pos[0] - .01
        y_text = pos[1] + pos[3] / 2.
        fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)

    # Turn off all ticks & spines
    for ax in axes:
        ax.set_axis_off()
    fig.show() 
开发者ID:theislab,项目名称:scanpy,代码行数:28,代码来源:palettes.py

示例14: _plot_scene

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def _plot_scene(self, scene):
        from matplotlib import colors
        from matplotlib import pyplot as plt

        cdict = {
            self.ORIG_SPACE : 'white',
            self.LABEL_SPACE : 'gray',
            self.ORIG_SOLID : 'black',
            self.LABEL_CONTAINER : 'red',
            self.TEMP_LIQUID : 'blue',
            self.LABEL_INTERIOR : 'green',
            self.LABEL_FLOOR_ADJACENT : 'yellow'
        }

        clist = list(set(cdict.values()))

        cmap = colors.ListedColormap(clist)
        bounds= range(len(clist)+1)
        norm = colors.BoundaryNorm(bounds, cmap.N)

        img = scene.copy()

        for i, c in cdict.iteritems():
            c_idx = clist.index(c)
            img[scene == i] = c_idx

        plt.imshow(img, cmap=cmap, norm=norm, interpolation='nearest') 
开发者ID:vicariousinc,项目名称:pixelworld,代码行数:29,代码来源:scene_annotation.py

示例15: _locate

# 需要导入模块: from matplotlib import colors [as 别名]
# 或者: from matplotlib.colors import BoundaryNorm [as 别名]
def _locate(self, x):
        '''
        Given a set of color data values, return their
        corresponding colorbar data coordinates.
        '''
        if isinstance(self.norm, (colors.NoNorm, colors.BoundaryNorm)):
            b = self._boundaries
            xn = x
        else:
            # Do calculations using normalized coordinates so
            # as to make the interpolation more accurate.
            b = self.norm(self._boundaries, clip=False).filled()
            xn = self.norm(x, clip=False).filled()

        # The rest is linear interpolation with extrapolation at ends.
        ii = np.searchsorted(b, xn)
        i0 = ii - 1
        itop = (ii == len(b))
        ibot = (ii == 0)
        i0[itop] -= 1
        ii[itop] -= 1
        i0[ibot] += 1
        ii[ibot] += 1

        db = np.take(b, ii) - np.take(b, i0)
        y = self._y
        dy = np.take(y, ii) - np.take(y, i0)
        z = np.take(y, i0) + (xn - np.take(b, i0)) * dy / db
        return z 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:31,代码来源:colorbar.py


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