python类cbook()的实例源码

mpl_plotter.py 文件源码 项目:scikit-hep 作者: scikit-hep 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _checks_and_wrangling(self, x, w):
        # Manage the input data in the same fashion as mpl
        if np.isscalar(x):
            x = [x]

        input_empty = (np.size(x) == 0)

        # Massage 'x' for processing.
        if input_empty:
            x = np.array([[]])
        else:
            x = cbook._reshape_2D(x)

        self.n_data_sets = len(x)  # number of datasets

        # We need to do to 'weights' what was done to 'x'
        if w is not None:
            w = cbook._reshape_2D(w)

        if w is not None and len(w) != self.n_data_sets:
            raise ValueError('weights should have the same shape as x')

        if w is not None:
            for xi, wi in zip(x, w):
                if wi is not None and len(wi) != len(xi):
                    raise ValueError('weights should have the same shape as x')

        return x, w
test_colorbar.py 文件源码 项目:matplotlib-colorbar 作者: ppinard 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_colorbar_example1():
    with cbook.get_sample_data('grace_hopper.png') as fp:
        data = np.array(plt.imread(fp))

    fig = plt.figure(figsize=(8, 6))
    ax = fig.add_subplot("111", aspect='equal')
    mappable = ax.imshow(data[..., 0], cmap='viridis')
    colorbar = Colorbar(mappable, location='lower left')
    colorbar.set_ticks([0.0, 0.5, 1.0])
    ax.add_artist(colorbar)
test_colorbar.py 文件源码 项目:matplotlib-colorbar 作者: ppinard 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_colorbar_example2():
    with cbook.get_sample_data('grace_hopper.png') as fp:
        data = np.array(plt.imread(fp))

    fig = plt.figure(figsize=(8, 6))
    ax = fig.add_subplot("111", aspect='equal')
    norm = matplotlib.colors.Normalize(vmin=-1.0, vmax=1.0)
    mappable = ax.imshow(data[..., 0], cmap='viridis', norm=norm)
    colorbar = Colorbar(mappable, location='lower left')
    colorbar.set_ticks([-1.0, 0, 1.0])
    ax.add_artist(colorbar)


问题


面经


文章

微信
公众号

扫码关注公众号