Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.
Close
From: Benjamin Root <ben.root@ou...>  20110531 18:04:13
Attachments:
Message as HTML

On Tue, May 31, 2011 at 12:58 PM, Eric Firing <efiring@...> 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@... > > <mailto:anthony.j.mannucci@...>> wrote: > > > > The following program seems to work with contour/contourf. However > > 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 twodimensional. The following program seems to bear > > this out. Are the arrays x and y below twodimensional, 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 1D, meshgrid is called to make 2D 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 documentation. > > Eric > > Well, (as a bit of a copout) 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 reword that? Ben Root 
From: Mannucci, Anthony J (335G) <anthony.mannucci@jp...>  20110531 15:35:12
Attachments:
Message as HTML

The following program seems to work with contour/contourf. However 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 twodimensional. The following program seems to bear this out. Are the arrays x and y below twodimensional, 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 Mannucci Supervisor, Ionospheric and Atmospheric Remote Sensing Group MailStop 138308, Tel > (818) 3541699 Jet Propulsion Laboratory, Fax > (818) 3935115 California Institute of Technology, Email > Tony.Mannucci@...<mailto:Tony.Mannucci@...> 4800 Oak Grove Drive, http://genesis.jpl.nasa.gov Pasadena, CA 91109 
From: Benjamin Root <ben.root@ou...>  20110531 15:50:51
Attachments:
Message as HTML

On Tue, May 31, 2011 at 10:34 AM, Mannucci, Anthony J (335G) < anthony.j.mannucci@...> wrote: > The following program seems to work with contour/contourf. However 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 twodimensional. The following program seems to bear this out. Are > the arrays x and y below twodimensional, 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 functions where this may or may not be true, and at some point we (the developers) should agree on basic input array handling and make it consistent across all plotting functions. So, technically speaking, the docs are "right", but should be clearer in this case. I will add it to my docfixing commit that I will do today. Ben Root 
From: Mannucci, Anthony J (335G) <anthony.mannucci@jp...>  20110606 15:52:17
Attachments:
Message as HTML

Benjamin, Thanks. I will point out that the contourf in Basemap behaves differently than that contourf in pylab. That is, in pylab, for contour(X,Y,Z) X,Y can be 1D whereas Z must be 2D. However, it appears that for contourf in Basemap: from mpl_toolkits.basemap import Basemap m=Basemap() g=m.contourf(X,Y,Z) X,Y and Z must all be 2D. Tony  Tony Mannucci Supervisor, Ionospheric and Atmospheric Remote Sensing Group MailStop 138308, Tel > (818) 3541699 Jet Propulsion Laboratory, Fax > (818) 3935115 California Institute of Technology, Email > Tony.Mannucci@...<mailto:Tony.Mannucci@...> 4800 Oak Grove Drive, http://genesis.jpl.nasa.gov Pasadena, CA 91109 From: Benjamin Root <ben.root@...<mailto:ben.root@...>> Date: Tue, 31 May 2011 08:50:22 0700 To: Tony Mannucci <Anthony.J.Mannucci@...<mailto:Anthony.J.Mannucci@...>> Cc: "matplotlibusers@...<mailto:matplotlibusers@...>" <matplotlibusers@...<mailto:matplotlibusers@...>> Subject: Re: [Matplotlibusers] Input array dimensions for contour or contourf On Tue, May 31, 2011 at 10:34 AM, Mannucci, Anthony J (335G) <anthony.j.mannucci@...<mailto:anthony.j.mannucci@...>> wrote: The following program seems to work with contour/contourf. However 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 twodimensional. The following program seems to bear this out. Are the arrays x and y below twodimensional, 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 functions where this may or may not be true, and at some point we (the developers) should agree on basic input array handling and make it consistent across all plotting functions. So, technically speaking, the docs are "right", but should be clearer in this case. I will add it to my docfixing commit that I will do today. Ben Root 
From: Eric Firing <efiring@ha...>  20110531 17:58:19

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@... > <mailto:anthony.j.mannucci@...>> wrote: > > The following program seems to work with contour/contourf. However > 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 twodimensional. The following program seems to bear > this out. Are the arrays x and y below twodimensional, 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 1D, meshgrid is called to make 2D 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 documentation. Eric > functions where this may or may not be true, and at some point we (the > developers) should agree on basic input array handling and make it > consistent across all plotting functions. > > So, technically speaking, the docs are "right", but should be clearer in > this case. I will add it to my docfixing commit that I will do today. > > Ben Root > > > >  > Simplify data backup and recovery for your virtual environment with vRanger. > Installation's a snap, and flexible recovery options mean your data is safe, > secure and there when you need it. Data protection magic? > Nope  It's vRanger. Get your free trial download today. > http://p.sf.net/sfu/questsfdev2dev > > > > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers 
From: Benjamin Root <ben.root@ou...>  20110531 18:04:13
Attachments:
Message as HTML

On Tue, May 31, 2011 at 12:58 PM, Eric Firing <efiring@...> 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@... > > <mailto:anthony.j.mannucci@...>> wrote: > > > > The following program seems to work with contour/contourf. However > > 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 twodimensional. The following program seems to bear > > this out. Are the arrays x and y below twodimensional, 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 1D, meshgrid is called to make 2D 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 documentation. > > Eric > > Well, (as a bit of a copout) 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 reword that? Ben Root 
From: Eric Firing <efiring@ha...>  20110531 18:28:53

On 05/31/2011 08:03 AM, Benjamin Root wrote: > > > On Tue, May 31, 2011 at 12:58 PM, Eric Firing <efiring@... > <mailto:efiring@...>> 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@... > <mailto:anthony.j.mannucci@...> > > <mailto:anthony.j.mannucci@... > <mailto:anthony.j.mannucci@...>>> wrote: > > > > The following program seems to work with contour/contourf. > However > > 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 twodimensional. The following program seems to > bear > > this out. Are the arrays x and y below twodimensional, 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 1D, meshgrid is called to make 2D 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 > documentation. > > Eric > > > Well, (as a bit of a copout) 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 reword that? It would not be correct. x and y must both be 2D, with the same shape as z; or they must both be 1D such that len(x) is the number of columns in z and len(y) is the number of rows. Eric > > Ben Root > 
From: Benjamin Root <ben.root@ou...>  20110531 18:37:56
Attachments:
Message as HTML

On Tue, May 31, 2011 at 1:28 PM, Eric Firing <efiring@...> wrote: > On 05/31/2011 08:03 AM, Benjamin Root wrote: > >> >> >> On Tue, May 31, 2011 at 12:58 PM, Eric Firing <efiring@... >> <mailto:efiring@...>> 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@... >> <mailto:anthony.j.mannucci@...> >> > <mailto:anthony.j.mannucci@... >> <mailto:anthony.j.mannucci@...>>> wrote: >> > >> > The following program seems to work with contour/contourf. >> However >> > 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 twodimensional. The following program seems to >> bear >> > this out. Are the arrays x and y below twodimensional, 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 1D, meshgrid is called to make 2D 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 >> documentation. >> >> Eric >> >> >> Well, (as a bit of a copout) 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 reword that? >> > > It would not be correct. > > x and y must both be 2D, with the same shape as z; or they must both be > 1D such that len(x) is the number of columns in z and len(y) is the number > of rows. > > Eric > > Gotcha, I didn't think about the mixed 1D and 2D 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 
From: Eric Firing <efiring@ha...>  20110531 19:39:02

On 05/31/2011 08:37 AM, Benjamin Root wrote: > > > On Tue, May 31, 2011 at 1:28 PM, Eric Firing <efiring@... > <mailto:efiring@...>> wrote: > > On 05/31/2011 08:03 AM, Benjamin Root wrote: > > > > On Tue, May 31, 2011 at 12:58 PM, Eric Firing > <efiring@... <mailto:efiring@...> > <mailto:efiring@... <mailto:efiring@...>>> 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@... > <mailto:anthony.j.mannucci@...> > <mailto:anthony.j.mannucci@... > <mailto:anthony.j.mannucci@...>> > > <mailto:anthony.j.mannucci@... > <mailto:anthony.j.mannucci@...> > <mailto:anthony.j.mannucci@... > <mailto:anthony.j.mannucci@...>>>> wrote: > > > > The following program seems to work with contour/contourf. > However > > 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 twodimensional. The following program seems to > bear > > this out. Are the arrays x and y below twodimensional, > 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 1D, meshgrid is called to make > 2D 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 > documentation. > > Eric > > > Well, (as a bit of a copout) 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 reword that? > > > It would not be correct. > > x and y must both be 2D, with the same shape as z; or they must > both be 1D such that len(x) is the number of columns in z and > len(y) is the number of rows. > > Eric > > > Gotcha, I didn't think about the mixed 1D and 2D 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." Good catch. Ian Thomas fixed the contouring algorithm so that it handles masked regions perfectly. Eric > > Ben Root > 
From: Benjamin Root <ben.root@ou...>  20110531 19:54:37
Attachments:
Message as HTML

On Tue, May 31, 2011 at 2:38 PM, Eric Firing <efiring@...> wrote: > On 05/31/2011 08:37 AM, Benjamin Root wrote: > >> >> >> On Tue, May 31, 2011 at 1:28 PM, Eric Firing <efiring@... >> <mailto:efiring@...>> wrote: >> >> On 05/31/2011 08:03 AM, Benjamin Root wrote: >> >> >> >> On Tue, May 31, 2011 at 12:58 PM, Eric Firing >> <efiring@... <mailto:efiring@...> >> <mailto:efiring@... <mailto:efiring@...>>> 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@... >> <mailto:anthony.j.mannucci@...> >> <mailto:anthony.j.mannucci@... >> <mailto:anthony.j.mannucci@...>> >> > <mailto:anthony.j.mannucci@... >> <mailto:anthony.j.mannucci@...> >> <mailto:anthony.j.mannucci@... >> <mailto:anthony.j.mannucci@...>>>> wrote: >> > >> > The following program seems to work with contour/contourf. >> However >> > 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 twodimensional. The following program seems >> to >> bear >> > this out. Are the arrays x and y below twodimensional, >> 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 1D, meshgrid is called to make >> 2D 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 >> documentation. >> >> Eric >> >> >> Well, (as a bit of a copout) 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 reword that? >> >> >> It would not be correct. >> >> x and y must both be 2D, with the same shape as z; or they must >> both be 1D such that len(x) is the number of columns in z and >> len(y) is the number of rows. >> >> Eric >> >> >> Gotcha, I didn't think about the mixed 1D and 2D 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." >> > > Good catch. Ian Thomas fixed the contouring algorithm so that it handles > masked regions perfectly. > > Eric > > When did that happen? I can make it a "versionadded" note so that users of older versions won't be confused. Ben Root 
From: Eric Firing <efiring@ha...>  20110531 20:23:36

> > > Good catch. Ian Thomas fixed the contouring algorithm so that it > handles masked regions perfectly. > > Eric > > > When did that happen? I can make it a "versionadded" note so that users > of older versions won't be confused. It was about 15 months ago. I think it is better to just delete any reference to the problem. Eric > > Ben Root > 