SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Mannucci, A. J (335G) <ant...@jp...> - 2011年05月31日 15:35:12
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 two-dimensional. The following program seems to bear 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 Mannucci
Supervisor, Ionospheric and Atmospheric Remote Sensing Group
 Mail-Stop 138-308, Tel > (818) 354-1699
 Jet Propulsion Laboratory, Fax > (818) 393-5115
 California Institute of Technology, Email > Ton...@jp...<mailto:Ton...@jp...>
 4800 Oak Grove Drive, http://genesis.jpl.nasa.gov
 Pasadena, CA 91109
From: Benjamin R. <ben...@ou...> - 2011年05月31日 15:50:51
On Tue, May 31, 2011 at 10:34 AM, Mannucci, Anthony J (335G) <
ant...@jp...> 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 two-dimensional. The following program seems to bear 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 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 doc-fixing commit that I will do today.
Ben Root
From: Mannucci, A. J (335G) <ant...@jp...> - 2011年06月06日 15:52:17
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
 Mail-Stop 138-308, Tel > (818) 354-1699
 Jet Propulsion Laboratory, Fax > (818) 393-5115
 California Institute of Technology, Email > Ton...@jp...<mailto:Ton...@jp...>
 4800 Oak Grove Drive, http://genesis.jpl.nasa.gov
 Pasadena, CA 91109
From: Benjamin Root <ben...@ou...<mailto:ben...@ou...>>
Date: 2011年5月31日 08:50:22 -0700
To: Tony Mannucci <Ant...@jp...<mailto:Ant...@jp...>>
Cc: "mat...@li...<mailto:mat...@li...>" <mat...@li...<mailto:mat...@li...>>
Subject: Re: [Matplotlib-users] Input array dimensions for contour or contourf
On Tue, May 31, 2011 at 10:34 AM, Mannucci, Anthony J (335G) <ant...@jp...<mailto:ant...@jp...>> 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 two-dimensional. The following program seems to bear 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 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 doc-fixing commit that I will do today.
Ben Root
From: Eric F. <ef...@ha...> - 2011年05月31日 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)
> <ant...@jp...
> <mailto:ant...@jp...>> 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 two-dimensional. The following program seems to bear
> 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 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 doc-fixing 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/quest-sfdev2dev
>
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Benjamin R. <ben...@ou...> - 2011年05月31日 18:04:13
On Tue, May 31, 2011 at 12:58 PM, Eric Firing <ef...@ha...> wrote:
> On 05/31/2011 05:50 AM, Benjamin Root wrote:
> >
> >
> > On Tue, May 31, 2011 at 10:34 AM, Mannucci, Anthony J (335G)
> > <ant...@jp...
> > <mailto:ant...@jp...>> 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 two-dimensional. The following program seems to bear
> > 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 documentation.
>
> Eric
>
>
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?
Ben Root
From: Eric F. <ef...@ha...> - 2011年05月31日 18:28:53
On 05/31/2011 08:03 AM, Benjamin Root wrote:
>
>
> On Tue, May 31, 2011 at 12:58 PM, Eric Firing <ef...@ha...
> <mailto:ef...@ha...>> wrote:
>
> On 05/31/2011 05:50 AM, Benjamin Root wrote:
> >
> >
> > On Tue, May 31, 2011 at 10:34 AM, Mannucci, Anthony J (335G)
> > <ant...@jp...
> <mailto:ant...@jp...>
> > <mailto:ant...@jp...
> <mailto:ant...@jp...>>> 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 two-dimensional. The following program seems to
> bear
> > 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
> documentation.
>
> Eric
>
>
> 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.
Eric
>
> Ben Root
>
From: Benjamin R. <ben...@ou...> - 2011年05月31日 18:37:56
On Tue, May 31, 2011 at 1:28 PM, Eric Firing <ef...@ha...> wrote:
> On 05/31/2011 08:03 AM, Benjamin Root wrote:
>
>>
>>
>> On Tue, May 31, 2011 at 12:58 PM, Eric Firing <ef...@ha...
>> <mailto:ef...@ha...>> wrote:
>>
>> On 05/31/2011 05:50 AM, Benjamin Root wrote:
>> >
>> >
>> > On Tue, May 31, 2011 at 10:34 AM, Mannucci, Anthony J (335G)
>> > <ant...@jp...
>> <mailto:ant...@jp...>
>> > <mailto:ant...@jp...
>> <mailto:ant...@jp...>>> 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 two-dimensional. The following program seems to
>> bear
>> > 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
>> documentation.
>>
>> Eric
>>
>>
>> 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.
>
> Eric
>
>
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
From: Eric F. <ef...@ha...> - 2011年05月31日 19:39:02
On 05/31/2011 08:37 AM, Benjamin Root wrote:
>
>
> On Tue, May 31, 2011 at 1:28 PM, Eric Firing <ef...@ha...
> <mailto:ef...@ha...>> wrote:
>
> On 05/31/2011 08:03 AM, Benjamin Root wrote:
>
>
>
> On Tue, May 31, 2011 at 12:58 PM, Eric Firing
> <ef...@ha... <mailto:ef...@ha...>
> <mailto:ef...@ha... <mailto:ef...@ha...>>> wrote:
>
> On 05/31/2011 05:50 AM, Benjamin Root wrote:
> >
> >
> > On Tue, May 31, 2011 at 10:34 AM, Mannucci, Anthony J (335G)
> > <ant...@jp...
> <mailto:ant...@jp...>
> <mailto:ant...@jp...
> <mailto:ant...@jp...>>
> > <mailto:ant...@jp...
> <mailto:ant...@jp...>
> <mailto:ant...@jp...
> <mailto:ant...@jp...>>>> 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 two-dimensional. The following program seems to
> bear
> > 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
> documentation.
>
> Eric
>
>
> 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.
>
> Eric
>
>
> 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."
Good catch. Ian Thomas fixed the contouring algorithm so that it 
handles masked regions perfectly.
Eric
>
> Ben Root
>
From: Benjamin R. <ben...@ou...> - 2011年05月31日 19:54:37
On Tue, May 31, 2011 at 2:38 PM, Eric Firing <ef...@ha...> wrote:
> On 05/31/2011 08:37 AM, Benjamin Root wrote:
>
>>
>>
>> On Tue, May 31, 2011 at 1:28 PM, Eric Firing <ef...@ha...
>> <mailto:ef...@ha...>> wrote:
>>
>> On 05/31/2011 08:03 AM, Benjamin Root wrote:
>>
>>
>>
>> On Tue, May 31, 2011 at 12:58 PM, Eric Firing
>> <ef...@ha... <mailto:ef...@ha...>
>> <mailto:ef...@ha... <mailto:ef...@ha...>>> wrote:
>>
>> On 05/31/2011 05:50 AM, Benjamin Root wrote:
>> >
>> >
>> > On Tue, May 31, 2011 at 10:34 AM, Mannucci, Anthony J (335G)
>> > <ant...@jp...
>> <mailto:ant...@jp...>
>> <mailto:ant...@jp...
>> <mailto:ant...@jp...>>
>> > <mailto:ant...@jp...
>> <mailto:ant...@jp...>
>> <mailto:ant...@jp...
>> <mailto:ant...@jp...>>>> 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 two-dimensional. The following program seems
>> to
>> bear
>> > 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
>> documentation.
>>
>> Eric
>>
>>
>> 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.
>>
>> Eric
>>
>>
>> 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."
>>
>
> 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 F. <ef...@ha...> - 2011年05月31日 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
>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /