Index: lib/matplotlib/colorbar.py
===================================================================
--- lib/matplotlib/colorbar.py	(revision 8214)
+++ lib/matplotlib/colorbar.py	(working copy)
@@ -193,6 +193,7 @@
                    'both': slice(1,-1),
                    'min': slice(1,1000000),
                    'max': slice(0,-1)}
+    EXTEND_OFFSET = 0.05 # Distance to add when drawing colorbar that extends
 
     def __init__(self, ax, cmap=None,
                            norm=None,
@@ -227,6 +228,7 @@
         self.patch = None
         self.dividers = None
         self.set_label('')
+        self.limits = None
         if cbook.iterable(ticks):
             self.locator = ticker.FixedLocator(ticks, nbins=len(ticks))
         else:
@@ -264,6 +266,20 @@
         if self.filled:
             self._add_solids(X, Y, C)
 
+    def set_limits(self, *lims):
+        '''
+        Set display limits for the colorbar. This is separate from setting
+        the norm, so that you can display just a portion of a colormap.
+        *lims* should be a pair of values, or None to not set a limit.
+        '''
+        if not lims:
+            self.limits = None
+        elif len(lims) != 2:
+            raise ValueError("limits should be of the form min,max or None.")
+
+        self.limits = lims
+        self.draw_all()
+
     def config_axis(self):
         ax = self.ax
         if self.orientation == 'vertical':
@@ -323,6 +339,9 @@
         ax.set_frame_on(False)
         ax.set_navigate(False)
         xy = self._outline(X, Y)
+        # Needed so that any limits that have been set will actually shrink
+        # the data limits
+        ax.ignore_existing_data_limits = True
         ax.update_datalim(xy)
         ax.set_xlim(*ax.dataLim.intervalx)
         ax.set_ylim(*ax.dataLim.intervaly)
@@ -585,25 +604,37 @@
             N += 1
         return N
 
+    def _limits_y(self):
+        '''
+        Return limits for the colorbar in the space of 0...1 using
+        the currently set data limits. If no limits are set, return
+        (0.0, 1.0).
+        '''
+        if self.limits:
+            return self.norm(self.limits)
+        else:
+            return 0.0, 1.0
+
     def _uniform_y(self, N):
         '''
         Return colorbar data coordinates for *N* uniformly
         spaced boundaries, plus ends if required.
         '''
+        ymin,ymax = self._limits_y()
         if self.extend == 'neither':
-            y = np.linspace(0, 1, N)
+            y = np.linspace(ymin, ymax, N)
         else:
             if self.extend == 'both':
                 y = np.zeros(N + 2, 'd')
-                y[0] = -0.05
-                y[-1] = 1.05
+                y[0] = ymin - self.EXTEND_OFFSET
+                y[-1] = ymax + self.EXTEND_OFFSET
             elif self.extend == 'min':
                 y = np.zeros(N + 1, 'd')
-                y[0] = -0.05
+                y[0] = ymin - self.EXTEND_OFFSET
             else:
                 y = np.zeros(N + 1, 'd')
-                y[-1] = 1.05
-            y[self._inside] = np.linspace(0, 1, N)
+                y[-1] = ymax + self.EXTEND_OFFSET
+            y[self._inside] = np.linspace(ymin, ymax, N)
         return y
 
     def _proportional_y(self):
@@ -611,16 +642,17 @@
         Return colorbar data coordinates for the boundaries of
         a proportional colorbar.
         '''
+        ymin,ymax = self._limits_y()
         if isinstance(self.norm, colors.BoundaryNorm):
-            b = self._boundaries[self._inside]
             y = (self._boundaries - self._boundaries[0])
             y = y / (self._boundaries[-1] - self._boundaries[0])
         else:
             y = self.norm(self._boundaries.copy())
+        y = y[(y >= ymin) & (y <= ymax)]
         if self.extend in ('both', 'min'):
-            y[0] = -0.05
+            y[0] = ymin - self.EXTEND_OFFSET
         if self.extend in ('both', 'max'):
-            y[-1] = 1.05
+            y[-1] = ymax + EXTEND_OFFSET
         yi = y[self._inside]
         norm = colors.Normalize(yi[0], yi[-1])
         y[self._inside] = norm(yi)
