I would like to draw a couple of contour plots. The plots are on
separate figures, but they should all have exactly the same color
mapping (i.e, the same Z value should correspond to the same color in
What's the best way to achieve this?
I think that all you will need is to specify the same cmap (if you are not using the default) and contour levels for both plots. You should not need to use the norm, unless you are doing something fancy; and in that case, all you need to do is specify the same norm for both plots. The real key, though, is explicitly specifying the set of contour levels that you want, and using the same one for both plots.
from pylab import * # yes, this is not recommended...
clevs = arange(0.3, 0.701, 0.1)
fig1 = figure()
contourf(rand(20,20), levels=clevs, extend='both')
fig2 = figure()
contourf(rand(30,40), levels=clevs, extend='both')
You need to use the extend argument only if you want values beyond the levels you specify to constitute open-ended ranges. For example, if you have data values from 0 to 10, but most are between 4 and 6, you could specify levels as numpy.arange(4, 6.01, 0.1) and use extend='both'. Then all values greater than 6 would get a color at one end, and all values less than 4 would get another color at the other end. If you use a colorbar, it will see the extend argument that was used in contourf, and draw the colorbar with pointed ends to indicate "anything over" and "anything under". As illustrated above.
On 07/26/2010 10:13 AM, Nikolaus Rath wrote:
From the documentation I gather that I should use the norm and extend
keyword arguments, but I wasn't really able to figure out what values
I have to pass and how the matplotlib.colors.Normalize instance works.