matplotlib pyplot contourf with 1-D array (vector)
rda.selin at gmail.com
Wed Aug 25 23:57:33 CEST 2010
I’m having a problem with the matplotlib.pyplot.contourf function. I
have a 1-D array of latitudes (mesolat), a 1-D array of longitudes
(mesolon), and a 1-D array of rainfall values (rain) at those
corresponding lat, lon points. After importing the necessary
libraries, and reading in these 1-D arrays, I do the following
p = Basemap(projection='lcc',llcrnrlon=-108.173,llcrnrlat=26.809999,
lon_0=-97.00, lat_0=37.00, resolution='i')
px,py = p(mesolon, mesolat)
prplvls = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
crain = p.contourf(px,py,rain,prplvls)
At this point the contourf function returns an error saying “Input z
must be a 2D array.” However, based on the documentation (http://
pyplot_api.html#matplotlib.pyplot.contourf) I thought that as long as
px, py, and rain are the same dimensions, everything should be fine.
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?
Thanks in advance for the help.
More information about the Python-list