|
110 | 110 |
|
111 | 111 | class ColorbarBase(cm.ScalarMappable):
|
112 | 112 | '''
|
| 113 | + Draw a colorbar in an existing axes. |
| 114 | +
|
| 115 | + This is a base class for the Colorbar class, which is |
| 116 | + the basis for the colorbar method and pylab function. |
| 117 | +
|
| 118 | + It is also useful by itself for showing a colormap. If |
| 119 | + the cmap kwarg is given but boundaries and values are left |
| 120 | + as None, then the colormap will be displayed on a 0-1 scale. |
| 121 | + To show the under- and over-value colors, specify the norm |
| 122 | + as colors.Normalize(clip=False). |
| 123 | + To show the colors versus index instead of on the 0-1 scale, |
| 124 | + use norm=colors.NoNorm. |
113 | 125 | '''
|
114 | 126 | _slice_dict = {'neither': slice(0,1000000),
|
115 | 127 | 'both': slice(1,-1),
|
@@ -348,10 +360,28 @@ def _process_values(self, b=None):
|
348 | 360 | return
|
349 | 361 | self._boundaries = npy.array(self.boundaries)
|
350 | 362 | return
|
| 363 | + # Neither boundaries nor values are specified; |
| 364 | + # make reasonable ones based on cmap and norm. |
351 | 365 | if isinstance(self.norm, colors.NoNorm):
|
352 |
| - b = npy.arange(self.norm.vmin, self.norm.vmax + 2) - 0.5 |
| 366 | + b = self._uniform_y(self.cmap.N+1) * self.cmap.N - 0.5 |
| 367 | + v = npy.zeros((len(b)-1,), dtype=npy.int16) |
| 368 | + v[self._inside] = npy.arange(self.cmap.N, dtype=npy.int16) |
| 369 | + if self.extend in ('both', 'min'): |
| 370 | + v[0] = -1 |
| 371 | + if self.extend in ('both', 'max'): |
| 372 | + v[-1] = self.cmap.N |
| 373 | + self._boundaries = b |
| 374 | + self._values = v |
| 375 | + return |
353 | 376 | else:
|
| 377 | + if not self.norm.scaled(): |
| 378 | + self.norm.vmin = 0 |
| 379 | + self.norm.vmax = 1 |
354 | 380 | b = self.norm.inverse(self._uniform_y(self.cmap.N+1))
|
| 381 | + if self.extend in ('both', 'min'): |
| 382 | + b[0] = b[0] - 1 |
| 383 | + if self.extend in ('both', 'max'): |
| 384 | + b[-1] = b[-1] + 1 |
355 | 385 | self._process_values(b)
|
356 | 386 |
|
357 | 387 | def _find_range(self):
|
|
0 commit comments