On 05/31/2011 05:50 AM, Benjamin Root wrote:
> On Tue, May 31, 2011 at 10:34 AM, Mannucci, Anthony J (335G)
> The following program seems to work with contour/contourf.
> the documentation for the contourf function states
> "/X/, /Y/, and /Z/ must be arrays with the same dimensions."
> I am finding that contour works if the dimension of X and Y
> 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
> 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)):
> 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
> 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?