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_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_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)
""" 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')