I am using matplotlib 1.3.0 and I have the following:
import matplotlib.pyplot as plt cmap = plt.cm.jet plt.contourf([[.12, .2], [.8, 2]], levels=[0, .1, .3, .5, 1, 3], cmap=cmap, vmin=0, vmax=3) plt.colorbar()
which produces:

A bit that I donβt understand, where do all the other colors go? As I understand it, specifying vmin=0 , vmax=3 , then the color bar should use the entire cmap range, as in this image:

which is created without providing the arguments vmin , vmax and levels . So ... what am I missing here?
EDIT 1
In response to tom10 and tcaswell. I would expect it to be the way you say it, but ... unfortunately, it is not. Take a look at this:
plt.contourf([[.12, .2], [.8, 3.2]], levels=[0, .1, .3, .5, 1, 3], cmap=cmap, vmin=0, vmax=3) plt.colorbar()
from:

Perhaps this is a little clarify: let's say I have data, and important features - about 0.1, but there are about 3, say. Therefore, I give it levels=[0, 0.005, 0.075, 0.1, 0.125, 0.15, 0.2, 1, 2.5, 2.75, 3, 3.25] and vmin=0, vmax=3.25 . Now I expect to see the whole range of colors, but instead, all the important data points from 0.005 to 0.125 will be in the blue area (using the standard plt.cm.jet color map). I think I think ... if I give levels=[0, 1, 2, 3], vmin=0, vmax=3 for some data that go from 0 to 3, I expect to see all the colors in this color to the map, but if I give levels=[0, 0.9, 0.1, 0.11, 1, 3], vmi=0, vmax=3 , I would expect the same thing to see all the colors in this color map, except for the display at the right intervals, instead I see a bunch of blues staining the 0-0.11 area, and some green / yellow colors in another part of the region. Hope this is ... a little clear.
EDIT 2
The same thing happens even if I don't give any norm or vmin, vmax .
EDIT 3
Referring to the tcaswell comment, we act as if ... for me, at least, it contradicts intuition. I expected the color to be incompatible with data points. I would expect that the entire range of colors from the color palette will be used all the time (except when vmin, vmax greater / less than the levels min, max values). In other words, looking at this code, I did some time ago (Python 3):
import matplotlib.colors as mc def addNorm(cmapData): cmapData['norm'] = mc.BoundaryNorm(cmapData['bounds'], cmapData['cmap'].N) return True def discretize(cmap, bounds): resCmap = {} resCmap['cmap'] = mc.ListedColormap( \ [cmap(i/len(bounds[1:])) for i in range(len(bounds[1:]))] ) resCmap['bounds'] = bounds addNorm(resCmap) return resCmap
then use it like:
levels = [0, .1, .3, .5, 1, 3] cmapData = discretize(plt.cm.jet, bounds=levels) plt.contourf([[.12, .2], [.8, 3.2]], levels=levels, cmap=cmapData['cmap'], norm=cmapData['norm']) plt.colorbar()
which gives a graph in which you can really distinguish the signs (0.1-0.5), i.e. they are no longer in the blue area using the above method with plt.cm.jet :

I mean, I know that I solved this, and some time ago too ... but my question is, I think ... how it turned out that the default in matplotlib is not so? I would expect it to be that way ... or maybe it's just a configuration / argument / something to enable this by default, what am I missing?