#!/usr/bin/python ''' Description: Create colorbar as separate figure Keywords: matplotlib, pyplot, colorbarcase, colormap, boundarynorm ''' from matplotlib import pyplot import matplotlib as mpl # Make a figure and axes with dimensions as desired. fig = pyplot.figure(figsize=(8,2)) ax1 = fig.add_axes([0.05, 0.80, 0.9, 0.15]) ax3 = fig.add_axes([0.05, 0.15, 0.9, 0.15]) # The third example illustrates the use of custom length colorbar # extensions, used on a colorbar with discrete intervals. cmap = mpl.colors.ListedColormap([[0., .4, 1.], [0., .8, 1.], [1., .8, 0.], [1., .4, 0.]]) cmap.set_over((1., 0., 0.)) cmap.set_under((0., 0., 1.)) bounds = [100, 200, 300, 400, 500] swbsTicks = [50, 150, 250, 350, 450, 550] norm = mpl.colors.BoundaryNorm(bounds, cmap.N) cb3 = mpl.colorbar.ColorbarBase(ax3, cmap=cmap, norm=norm, boundaries=[-10]+swbsTicks+[10], extend='both', # Make the length of each extension # the same as the length of the # interior colors: extendfrac='auto', ticks=bounds, spacing='uniform', orientation='horizontal') cb3.set_label('Custom extension lengths, some other units') pyplot.show()