Hi All,

I'm new to the list, and have hit a snag that I can't find an answer for in the Cookbook or Gallery.  Basically, I would like to define a color bar that is valid for a range of 0 - 10, but only display the range that is being mapped, say 5 - 7.

Is this possible?

Below is the code that I'm using.

Thanks,

Roger
--------------------------------
#! /usr/bin/python

'''
Make a colorbar as a separate figure.
'''
import matplotlib
from matplotlib import pyplot, mpl

# Make a figure and axes with dimensions as desired.
fig = pyplot.figure(figsize=(5,2))
ax1 = fig.add_axes([0.05, 0.65, 0.9, 0.15])

# SETUP A CUSTOM COLOR RAMP
      

# HYDRO SAMPLE COLOR RAMP
cdict = {'blue': [[0.0, 0.25098039215686274, 0.25098039215686274],
                   [0.10000000000000001, 1.0, 1.0],
                   [0.20000000000000001, 1.0, 1.0],
                   [0.29999999999999999, 1.0, 1.0],
                   [0.40000000000000002, 0.75294117647058822, 0.75294117647058822],
                   [0.5, 0.25098039215686274, 0.25098039215686274],
                   [0.59999999999999998, 0.25098039215686274, 0.25098039215686274],
                   [0.69999999999999996, 0.25098039215686274, 0.25098039215686274],
                   [0.80000000000000004, 0.25098039215686274, 0.25098039215686274],
                   [0.90000000000000002, 1.0, 1.0],
                   [1.0, 0.88235294117647056, 0.88235294117647056]],
          'green': [[0.0, 0.0, 0.0],
                   [0.10000000000000001, 0.25098039215686274, 0.25098039215686274],
                   [0.20000000000000001, 0.62745098039215685, 0.62745098039215685],
                   [0.29999999999999999, 0.8784313725490196, 0.8784313725490196],
                   [0.40000000000000002, 1.0, 1.0],
                   [0.5, 1.0, 1.0],
                   [0.59999999999999998, 1.0, 1.0],
                   [0.69999999999999996, 0.62745098039215685, 0.62745098039215685],
                   [0.80000000000000004, 0.12549019607843137, 0.12549019607843137],
                   [0.90000000000000002, 0.62745098039215685, 0.62745098039215685],
                   [1.0, 0.8784313725490196, 0.8784313725490196]],
           'red': [[0.0, 0.25098039215686274, 0.25098039215686274],
                   [0.10000000000000001, 0.0, 0.0],
                   [0.20000000000000001, 0.0, 0.0],
                   [0.29999999999999999, 0.25098039215686274, 0.25098039215686274],
                   [0.40000000000000002, 0.25098039215686274, 0.25098039215686274],
                   [0.5, 0.50196078431372548, 0.50196078431372548],
                   [0.59999999999999998, 1.0, 1.0],
                   [0.69999999999999996, 1.0, 1.0],
                   [0.80000000000000004, 1.0, 1.0],
                   [0.90000000000000002, 1.0, 1.0], [1.0, 1.0, 1.0]]}


cmap = matplotlib.colors.LinearSegmentedColormap('my_colormap',cdict,256)

# Set the colormap and norm to correspond to the data for which
# the colorbar will be used.
#cmap = mpl.cm.cool
norm = mpl.colors.Normalize(vmin=5, vmax=10)

cb1 = mpl.colorbar.ColorbarBase(ax1,
                                cmap=cmap,
                                norm=norm,
                                orientation='horizontal')

cb1.set_label('Some Units')

pyplot.show()