Thanks, Eric,
Yes, that works for the stripped down version, but not for what I am trying
to do. The examples I have given have the range of one of the plots nicely
fitting inside that of the other (ie, plot 1 range 15 to 26, plot 2 range 17
to 23), but sometimes with what I am doing I have, for example, plot 1
range 15 to 23 and plot 2 range 17 to 25. In this case, passing the levels
from plot 1 to plot 2 means that levels 24 and 25 of plot 2 are stripped
away; this, at least, is what I think is happening because I have white
areas of my plot that weren't there before. It seems to me that it would be
quite useful to have the option to override the colorbar range, setting it
to be the same as defined by clim, or some other values.
As a solution for now, I think I will just use one colorbar for the two
plots. Thanks for your help with this, and the tip about being explicit in
my programs!
-Evan
On 3/27/07, Eric Firing <[EMAIL PROTECTED]> wrote:
Evan,
OK, I see what the problem is: you need to tell the second contour
command to use the same contour levels as the first one is using.
Something like this:
figure(1)
CS1 = contourf(x)
clim(cmin, cmax)
colorbar()
figure(2)
CS2 = contourf(y, levels=CS1.levels)
clim(cmin, cmax)
colorbar()
Does this give the desired result?
The big difference between pcolor and contourf in this context is that
pcolor is automatically generating a colormap with 256 colors, and may
use any or all of those colors, so the colorbar is effectively
continuous. Contourf works with a small discrete set of colors taken
from such a colormap, so colorbar shows the same discrete set. The
boundaries are either generated automatically in contourf, or set via
the levels kwarg. Colorbar gets the boundaries from the output of the
contourf call, which pylab saves and passes along to colorbar even if
you don't do so explicitly yourself. But pylab has no way of knowing
that you want the contour levels in the second figure to match the
first, so you have to be explicit.
Usually at this point someone chimes in to point out the virtues of
being explicit in your program even when you don't have to...
Eric
Evan Mason wrote:
> Hi Eric, the following lines below will show this. Interestingly, the
> correct (or, at least, what I want) behaviour results from using pcolor,
> but not with contourf.
>
>
> a = arange(12, 27, .5)
> b = arange(17, 23, .5)
> x, y = meshgrid(a, b)
>
> # get max and min for clim
> cmin = min(x.min(), y.min()) # cmin = 12
> cmax = max(x.max(), y.max()) # cmax = 26.5
>
> figure(1)
> contourf(x)
> #pcolor(x)
> clim([cmin, cmax])
> colorbar()
> figure(2)
> contourf(y)
> #pcolor(y)
> clim([cmin, cmax])
> colorbar()
>
>
> -Evan
>
>
>
>
> On 3/27/07, *Eric Firing* < [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>> wrote:
>
> Evan,
>
> That is getting clearer, but it still seems to me that no override
> should be needed in this case; it should "just work", so if it
doesn't,
> either there is a bug in mpl or a bug in the code. It would be most
> helpful if you would write a stripped-down simplest-possible script
> that
> illustrates the problem. Then I can either show how to fix the
script,
> or I can use the script to help me track down the mpl bug, if that
is
> the problem.
>
> Eric
>
> Evan Mason wrote:
> > Hi Eric
> >
> > I am using matplotlib-0.90.0.
> >
> > I am making 2 contourf subplots of temperature values which have
> similar
> > but not equal ranges. In subplot1 the range is 15-25; in
> subplot2 it is
> > 16 to 24. I use clim, giving it the max and min values obtained
> from a
> > comparison of subplot1 and 2; i.e., I use clim([15, 25]) on both
> > subplots. The two subplots display exactly as I want them to.
> >
> > Next, I want 2 colorbars to go with the two subplots. I want the
> range
> > of each colorbar to be the same, set as the clim values (15 and
25).
> > This happens for subplot1, but not for subplot2, which shows the
> range
> > 16-24, following its input data range and not the clim values.
> >
> > So what I want to know is if it is possible to overide the
colorbar
> > limits, setting them to 15-25?
> >
> > I hope that's clearer now, thanks, Evan
> >
> >
> >
> > On 3/27/07, * Eric Firing* < [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>
> > <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>> wrote:
> >
> > Evan,
> >
> > It is still not quite clear to me what you want versus what
> you are
> > getting. With recent versions of mpl, the colorbar
> automatically uses
> > the same color boundaries as contourf, if that is what the
> colorbar is
> > tracking. What version of mpl are you using?
> >
> > (With the most recent mpl I see that there is a strange bug
> such that
> > setting clim clobbers the axis tick labeling for the
> colorbar--yet
> > another thing that needs to be figured out and fixed.)
> >
> >
>
>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users