matplotlib pyplot contourf with 1-D array (vector)

becky_s rda.selin at gmail.com
Thu Aug 26 08:58:14 EDT 2010


On Aug 26, 1:52 am, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Wed, 25 Aug 2010 14:57:33 -0700 (PDT), becky_s <rda.selin at gmail.com>
> declaimed the following in gmane.comp.python.general:
>
>
>
> > px,py = p(mesolon, mesolat)
>
>         For my elucidation, what does that      p(x,y)  actually do? Especially
> as you appear to expect the result to be split into separate x and y
> afterwards? I can't find it defined in either matplotlib nor numpy.

p was declared as a basemap object in the previous statement, which
sets up a map projection.  Calling p(mesolon, mesolat) converts those
lons, lats to units in that map projection and stores them in px,py.
(See http://matplotlib.sourceforge.net/matplotlib.toolkits.basemap.basemap.html
for more info on basemap.)


>
> > pyplot_api.html#matplotlib.pyplot.contourf) I thought that as long as
> > px, py, and rain are the same dimensions, everything should be fine.
>
>         And are they? You don't demonstrate that you've checked for that

I did a simple print px.shape, rain.shape, etc. to check.  They are
all size (135,).


>
> > Apparently that is not the case?  If 1D arrays are not allowed in
> > contourf, then how can I change my data into a 2D array?
>
>         Also note (jumping to your follow up) that contourf is described as
> having a potential problem with masked arrays (whatever those are) for
> "Z"


My problem isn't with the masked arrays as much as it is with rain
being a 1D array.  IDL can handle contouring 1D arrays with missing
variables lickety-split, so I was really hoping Python could as well.

Also, numpy.ma is the masked array library.  See
http://docs.scipy.org/doc/numpy/reference/routines.ma.html.




More information about the Python-list mailing list