DataBandit DataBandit - 3 months ago 45
Python Question

Using Python basemap etopo() generates IndexError

I'm trying to basemap working. I've installed matplotlib, basemap, and Pillow successfully and can plot basic plots. The code below works for me.

from mpl_toolkits.basemap import Basemap
from PIL import Image
import matplotlib.pyplot as plt

m = Basemap(projection = 'mill',
llcrnrlat = -90,
llcrnrlon = -180,
urcrnrlat = 90,
urcrnrlon = 180,
resolution = 'c')

m.drawcoastlines()
#m.etopo()

plt.show()


However, uncommenting the 'etopo()' command yields the following error.

Traceback (most recent call last):

File "C:\Users\xxx\Desktop\helper.py", line 13, in <module> m.etopo()

File "C:\Python35-32\lib\site-packages\mpl_toolkits\basemap\__init__.py", line 4061, in etopo return self.warpimage(image='etopo',scale=scale,**kwargs)

File "C:\Python35-32\lib\site-packages\mpl_toolkits\basemap\__init__.py", line 4167, in warpimage np.concatenate((self._bm_lons,self._bm_lons+360),1)

IndexError: axis 1 out of bounds [0, 1)


I've tried reinstalling and updating all relevant packages, but that hasn't worked. I also can't find anything on this error for this situation. I'm on Windows 8.1 with 32 bit Python 3.5.1

Answer

If you are just testing Basemap and .etopo() functionality, I updated your script:

from mpl_toolkits.basemap import Basemap
from PIL import Image
import matplotlib.pyplot as plt

# make a miller cylindrical projection with defaults
m = Basemap('mill')

m.drawcoastlines()
# now displays topo relief image
m.etopo()

plt.show()