 # Contour plots with same color mapping

Hello,

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
all plots).

What's the best way to achieve this?

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.

Thanks,

-Nikolaus

···

--
»Time flies like an arrow, fruit flies like a Banana.«

PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C

Hello,

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
all plots).

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.

e.g.:

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')
colorbar()
fig2 = figure()
contourf(rand(30,40), levels=clevs, extend='both')
colorbar()
show()

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.

Eric

···

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.

Thanks,

-Nikolaus