contour extent

Eric,

Craig is right, contour and contourf are ignoring the 'extent' kwarg. I
just tried the contour_image.py demo you referred to. I changed the value
of the image extent parameters, and they still do not show up.

Cheers,
Curtis

      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * Curtis S. Cooper, Graduate Research Assistant *
   * Lunar and Planetary Laboratory, University of Arizona *
   * http://www.lpl.arizona.edu/~curtis/ *
   * Kuiper Space Sciences, Rm. 318 *
    * 1629 E. University Blvd., *
     * Tucson, AZ 85721 * * * * * * * * * * * * * * *
      * Wk: (520) 621-1471 *
       * * * * * * * * * * * *

Curtis Cooper wrote:

Eric,

Craig is right, contour and contourf are ignoring the 'extent' kwarg. I
just tried the contour_image.py demo you referred to. I changed the value
of the image extent parameters, and they still do not show up.

Cheers,
Curtis

Curtis,

What do you mean by "do not show up"? In contour_image.py, I changed

extent = (-3,4,-4,3)
to
extent = (-30,40,-40,30)

and the three subplots that use extent changed their x and y ranges by a factor of 10, as expected.

Either there is a version problem or there is a misunderstanding, so you will need to be more specific. Please provide a minimal script that doesn't do what you think it should, and specify what it is that you think it should do.

Thanks.

Eric

Hi Eric,

I'm sorry; you are correct. I will examine your example more carefully.
What doesn't seem to work is when I don't use imshow at all but just do
contour(Z, extent=extent). That is, the axes are just rows and columns of
the pixels, not the extent I specified, whereas the extent I specified
shows up when I only use imshow.

Thanks,
Curtis

      * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * Curtis S. Cooper, Graduate Research Assistant *
   * Lunar and Planetary Laboratory, University of Arizona *
   * http://www.lpl.arizona.edu/~curtis/ *
   * Kuiper Space Sciences, Rm. 318 *
    * 1629 E. University Blvd., *
     * Tucson, AZ 85721 * * * * * * * * * * * * * * *
      * Wk: (520) 621-1471 *
       * * * * * * * * * * * *

···

On Mon, 13 Feb 2006, Eric Firing wrote:

Curtis Cooper wrote:
> Eric,
>
> Craig is right, contour and contourf are ignoring the 'extent' kwarg. I
> just tried the contour_image.py demo you referred to. I changed the value
> of the image extent parameters, and they still do not show up.
>
> Cheers,
> Curtis

Curtis,

What do you mean by "do not show up"? In contour_image.py, I changed

extent = (-3,4,-4,3)
to
extent = (-30,40,-40,30)

and the three subplots that use extent changed their x and y ranges by a
factor of 10, as expected.

Either there is a version problem or there is a misunderstanding, so you
will need to be more specific. Please provide a minimal script that
doesn't do what you think it should, and specify what it is that you
think it should do.

Thanks.

Eric

Curtis,

Now I see what you mean. The problem is that the extent kwarg works only if the origin kwarg is also set and is not None. I have changed the docstring accordingly. There was a reason I made that requirement, but possibly it could be relaxed. The alternative is to simply generate X and Y arrays that specify the coordinates of your Z points, and then call contour(X, Y, Z, ...).

Eric

Curtis Cooper wrote:

···

Hi Eric,

I'm sorry; you are correct. I will examine your example more carefully.
What doesn't seem to work is when I don't use imshow at all but just do
contour(Z, extent=extent). That is, the axes are just rows and columns of
the pixels, not the extent I specified, whereas the extent I specified
shows up when I only use imshow.

Thanks,
Curtis

Now I see what you mean. The problem is that the extent kwarg works
only if the origin kwarg is also set and is not None. I have changed
the docstring accordingly. There was a reason I made that requirement,
but possibly it could be relaxed. The alternative is to simply generate
X and Y arrays that specify the coordinates of your Z points, and then
call contour(X, Y, Z, ...).

I think extent should work even if origin is not set, but at least if the
documentation is clear about this, users can figure out the right thing to
do easily enough.

The alternative you mention does not allow plotting of the y-axis in
reverse. For example, I often put pressure decreasing upward on the
y-axis of my plots. It would be nice if contour(X, Y, Z, ...) respected
my choice of ordering.

Cheers,
Curtis

Curtis,

Curtis Cooper wrote:

Now I see what you mean. The problem is that the extent kwarg works
only if the origin kwarg is also set and is not None. I have changed
the docstring accordingly. There was a reason I made that requirement,
but possibly it could be relaxed. The alternative is to simply generate
X and Y arrays that specify the coordinates of your Z points, and then
call contour(X, Y, Z, ...).

I think extent should work even if origin is not set, but at least if the
documentation is clear about this, users can figure out the right thing to
do easily enough.

OK, probably I will make the change (to allow use of extent without origin) soon, but I did not want to do it in too much of a hurry.

The alternative you mention does not allow plotting of the y-axis in
reverse. For example, I often put pressure decreasing upward on the
y-axis of my plots. It would be nice if contour(X, Y, Z, ...) respected
my choice of ordering.

But it does. The X and Y arrays give the coordinates of the Z points. If you want to reverse the Y axis, say to have Y increase downward, then you do something like this:

a = gca()
a.set_ylim(a.get_ylim()[::-1])

There are many other ways to do it, but the point is that the axes are drawn with the first ylim value at the bottom and the second at the top, so to reverse the axis you simply reverse the order of the y limits. Similarly for the x-axis.

Eric

But it does. The X and Y arrays give the coordinates of the Z points.
If you want to reverse the Y axis, say to have Y increase downward, then
  you do something like this:

a = gca()
a.set_ylim(a.get_ylim()[::-1])

There are many other ways to do it, but the point is that the axes are
drawn with the first ylim value at the bottom and the second at the top,
  so to reverse the axis you simply reverse the order of the y limits.
Similarly for the x-axis.

Fair enough, but notice that if I use imshow(Z, extent=[xmin, xmax,
ymax, min]), it displays the image with the ymax extent at the bottom and
ymin at the top of the y-axis, as I intended. For contour, the extent is
always displayed in increasing order in each axis.

Curtis,

I have added support for the extent kwarg in the case with origin=None--that is, the case in which contour is being used alone, not superimposed on an image.

The intention is that extent = (x0,x1,y0,y1) with origin = None will make (x0,y0) the coordinates of Z[0,0] and (x1,y1) the coordinates of Z[-1,-1]. In other words, it provides an easy way to generate equally-spaced coordinates specified by the end points, and corresponding in a simple and unambiguous way to the Z array. Beyond that, the orientation of the axes is determined in the usual way. This seems logical to me.

Curtis Cooper wrote:

But it does. The X and Y arrays give the coordinates of the Z points.
If you want to reverse the Y axis, say to have Y increase downward, then
you do something like this:

a = gca()
a.set_ylim(a.get_ylim()[::-1])

There are many other ways to do it, but the point is that the axes are
drawn with the first ylim value at the bottom and the second at the top,
so to reverse the axis you simply reverse the order of the y limits.
Similarly for the x-axis.

Fair enough, but notice that if I use imshow(Z, extent=[xmin, xmax,
ymax, min]), it displays the image with the ymax extent at the bottom and
ymin at the top of the y-axis, as I intended. For contour, the extent is
always displayed in increasing order in each axis.

With respect to the comparison to imshow: is there any circumstance under which the plotting the same data with the same origin and extent options on the same axes (as in contour_image.py) results in a mis-registration--any sort of mismatch between the image view and the contour view?

I still can't find anything wrong; but if you send me a script that illustrates incorrect behavior, I will certainly look at it.

Thanks.

Eric