 # Using the same color range for multiple plots

Hi guys,

I've tried to google this and look through the examples but its not quite
working for me. Say I have two sets of data I want to make contour plots out
of

from pylab import *

x=arange(-3.0,3.0,.025)

y=arange(-2.0,2.0,.025)

X,Y = meshgrid(x,y)

Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)

Now if I would go

plt1 = subplot(211)
contourf(X,Y,Z1)
colorbar()

plt2 = subplot(212)
contourf(X,Y,Z2)
colorbar()

we would see that the same colors correspond to different numerical values,
because the ranges of Z1 and Z2 are different. I want it to be defined on
the same range, so that red on plt1 corresponds to the same numerical Z
value as red on plt2. How do I go about doing that?

···

--
View this message in context: http://www.nabble.com/Using-the-same-color-range-for-multiple-plots-tp22592487p22592487.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

cneff wrote:

Hi guys,

I've tried to google this and look through the examples but its not quite
working for me. Say I have two sets of data I want to make contour plots out
of

from pylab import *

x=arange(-3.0,3.0,.025)

y=arange(-2.0,2.0,.025)

X,Y = meshgrid(x,y)

Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)

Now if I would go

plt1 = subplot(211)
contourf(X,Y,Z1)
colorbar()

plt2 = subplot(212)
contourf(X,Y,Z2)
colorbar()

we would see that the same colors correspond to different numerical values,
because the ranges of Z1 and Z2 are different. I want it to be defined on
the same range, so that red on plt1 corresponds to the same numerical Z
value as red on plt2. How do I go about doing that?

Instead of relying on autoscaling to set the color levels, set them explicitly to the same set of values in both calls to contourf by adding a fourth argument.

e.g.

levs = arange(0,1.01,0.1)

...

contourf(X, Y, Z1, levs)

...

contourf(X, Y, Z2, levs)

...

Eric