IndexError' too many indices' in basemap contour

IndexError’ too many indices’ in basemap contour

Hi!

I try to plot some interpolated data on a map and get an error saying there are too many indices. When I use contour in matplotlib without basemap I don’t get the error. Also the map without a contour plot on it works. Maybe some of you know what I do wrong?

Here is my code:

···

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.mlab import griddata

from mpl_toolkits.basemap import Basemap

yi = np.linspace(min(Lat),max(Lat),100)

xi = np.linspace(min(Lon),max(Lon),50)

lon,lat,var = np.array(Lon), np.array(Lat), np.array(Var)

zi = griddata(lon,lat,var,xi,yi)

map = Basemap(projection=‘cyl’, llcrnrlat=67, urcrnrlat=73,\

       llcrnrlon=4, urcrnrlon=20, resolution='h')

map.drawcoastlines()

map.drawmeridians(np.arange(0,360,1))

map.drawparallels(np.arange(-90,90,1))

xlon, ylat = map(xi,yi)

cs = map.contour(xlon,ylat,zi)

plt.show()


and this is the error message:

cs = map.contour(xlon,ylat,zi)

File “/usr/local/lib/python2.6/dist-packages/mpl_toolkits/basemap/init.py”, line 2820, in contour

xx = x[x.shape[0]/2,:]

IndexError: too many indices

Any help appreciated!

Sünnje

Sunnje: xlon, xlat must be 2d arrays (with the same shape as zi)
when used with the contourf basemap method. You can make them into
2d arrays with meshgrid.

-Jeff
···

On 11/5/10 5:08 AM, Basedow Sünnje Linnéa wrote:

IndexError’ too many indices’ in basemap contour
Hi!

      I try to plot some interpolated data on a map and get an error

saying there are too many indices. When I use contour in
matplotlib without basemap I don’t get the error. Also the map
without a contour plot on it works. Maybe some of you know
what I do wrong?

      Here is my code:

      -------------

      import numpy as np

      import matplotlib.pyplot as plt

      from matplotlib.mlab import griddata

      from mpl_toolkits.basemap import Basemap

                                                                                              

      yi = np.linspace(min(Lat),max(Lat),100)

      xi = np.linspace(min(Lon),max(Lon),50)

      lon,lat,var = np.array(Lon), np.array(Lat), np.array(Var)

      zi = griddata(lon,lat,var,xi,yi)



      map = Basemap(projection='cyl', llcrnrlat=67, urcrnrlat=73,\

                 llcrnrlon=4, urcrnrlon=20, resolution='h')

                                                                                               

      map.drawcoastlines()



      map.drawmeridians(np.arange(0,360,1))

      map.drawparallels(np.arange(-90,90,1))



      xlon, ylat = map(xi,yi)

      cs = map.contour(xlon,ylat,zi)



      plt.show()

      ---------------



      and this is the error message:



      cs = map.contour(xlon,ylat,zi)

      File

“/usr/local/lib/python2.6/dist-packages/mpl_toolkits/basemap/init.py”,
line 2820, in contour

        xx = x[x.shape[0]/2,:]

      IndexError: too many indices



      Any help appreciated!

      Sünnje