On Tue, May 31, 2011 at 1:28 PM, Eric Firing <efiring@hawaii.edu> wrote:
On 05/31/2011 08:03 AM, Benjamin Root wrote:

On Tue, May 31, 2011 at 12:58 PM, Eric Firing <efiring@hawaii.edu
<mailto:efiring@hawaii.edu>> wrote:

   On 05/31/2011 05:50 AM, Benjamin Root wrote:
    > On Tue, May 31, 2011 at 10:34 AM, Mannucci, Anthony J (335G)
    > <anthony.j.mannucci@jpl.nasa.gov
    > <mailto:anthony.j.mannucci@jpl.nasa.gov
   <mailto:anthony.j.mannucci@jpl.nasa.gov>>> wrote:
    >     The following program seems to work with contour/contourf.
    >     the documentation for the contourf function states
    >     contour(X,Y,Z)
    > "/X/, /Y/, and /Z/ must be arrays with the same dimensions."
    >     I am finding that contour works if the dimension of X and Y
   are 1,
    >     but Z must be two-dimensional. The following program seems to
    >     this out. Are the arrays x and y below two-dimensional, or is the
    >     documentation misleading? Thanks for your help.
    >     import numpy as N
    >     import pylab as PLT
    >     lons = N.linspace(-5.,5.,5) # Is this a one or two
   dimensional array?
    >     lats = N.linspace(-3.,3.,4)
    >     z = N.zeros((len(lats), len(lons)))
    >     for i in range(len(lons)):
    >          for j in range(len(lats)):
    >              z[j,i]=i+j
    >     PLT.clf()
    >     PLT.contourf(lons,lats,z)
    >     PLT.colorbar()
    >     PLT.show()
    >     -Tony
    > Tony,
    > contour and contourf seems to take advantage of numpy's broadcasting
    > feature, so it is probably more correct to say that X and Y must
   be at
    > least broadcastable to the shape of Z.  I think there are a number of

   Not quite; if x and y are 1-D, meshgrid is called to make 2-D versions,
   which must then match Z. Broadcasting is not used or supported. So, the
   contour docstring was not updated when this functionality was added,
   long ago.  Consider it an undocumented feature, in need of


Well, (as a bit of a cop-out) in my edit, I didn't say that they were
broadcasted, only that they must be broadcastable to the same shape.
Would that suffice, or should I re-word that?

It would not be correct.

x and y must both be 2-D, with the same shape as z; or they must both be 1-D such that len(x) is the number of columns in z and len(y) is the number of rows.


Gotcha, I didn't think about the mixed 1-D and 2-D case.

In addition, is the note in the contour doc about masked arrays still valid, or can this be removed/updated?

"*Z* may be a masked array, but filled contouring may not handle internal masked regions correctly."

Ben Root