Using Basemap 1.0.7 in Python 3.6

I'm creating a filled contour plot using m.contourf() form basemap(http://matplotlib.org/basemap/api/basemap_api.html#mpl_toolkits.basemap.Basemap.contourf). For some reason ever since I upgraded to Python 3.6 and upgraded my packages numpy, scipy pandas etc, I keep getting this error. It worked fine in Python2.7 though.

Error,

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/karthik/Documents/code/test_countourf.py", line 99, in <module>
    map.contourf(x, y, _arr, zorder = 0, cmap = _cmap, norm = cNorm, levels=levels)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mpl_toolkits/basemap/__init__.py", line 521, in with_transform
    return plotfunc(self,x,y,data,*args,**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mpl_toolkits/basemap/__init__.py", line 3644, in contourf
    xx = x[x.shape[0]/2,:]
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

My suspicion was that x.shape[0]/2 gives a float(since Python 3 I think) instead of an integer which might be the error since I didn't see the error in Python 2.7.

Any ideas on how to fix it in Python 3.6?

Thanks!

 

You could replace x.shape[0]/2 by x.shape[0]//2 as a quick fix, just as it's already been done in the newest version. In general, you may need to update matplotlib as well as basemap.

转载于:https://my.oschina.net/voole/blog/1831154

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值