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)
def test_colorbar_example1():
    with cbook.get_sample_data('grace_hopper.png') as fp:
        data = np.array(plt.imread(fp))

    fig = plt.figure()
    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)
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)
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
Beispiel #5
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)
"""
Draw the example used in the README file.
"""

# Standard library modules.

# Third party modules.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook

# Local modules.
from matplotlib_colorbar.colorbar import Colorbar

# Globals and constants variables.


plt.figure()
data = np.array(plt.imread(cbook.get_sample_data('grace_hopper.png')))
mappable = plt.imshow(data[..., 0], cmap='viridis')
colorbar = Colorbar(mappable, location='lower left')
colorbar.set_ticks([0.0, 0.5, 1.0])
plt.gca().add_artist(colorbar)
plt.savefig('example1.png', bbox_inches='tight')