예제 #1
0
def add_colorbar(ax, im, loc='center left', label=None):
    from matplotlib_colorbar.colorbar import Colorbar
    cbar = Colorbar(im, location=loc, border_pad=0.5)
    if label is not None:
        cbar.set_label(label)
    cbar.set_alpha(1)
    #cbar.draw_all()
    ax.add_artist(cbar)
예제 #2
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)
예제 #3
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)
예제 #4
0
def create_figure():
    fig = plt.figure()
    ax = fig.add_subplot("111")

    data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    mappable = ax.imshow(data)

    colorbar = Colorbar(mappable)
    ax.add_artist(colorbar)

    return fig, ax, colorbar