Indexerror When Using Some Projections With Basemap And Contourf In Python 3.6.1
Solution 1:
In response to lanadaquenada (I cannot coment it seems)
Based on Serenity's post you actually need to modify the basemap code, rather than your code. Basemap is old and not really supported anymore. It was created when python 2.x was released and it appears it utilised the python 2 integer division. Python 3 now does division "correctly", but some old code was created to take advantage of python 2 division.
While using python3 and matplotlib 1.5.3 I would receive a warning about this issue, but it was not fatal. After upgrading to matplotlib 2.0.2 this error became fatal and my googling lead to your post.
Therefore following Serenity's advice you need to Manually change lines with
xx[x.shape[0]/2, :]
to
xx[x.shape[0]//2, :]
For me this was 3452 and 3644 in path_where_your_python_libraries_are_installed/site-packages/mpl_toolkits/basemap/__init__.py
I am using basemap version 1.0.7.
I needed to make this change when transitioning from matplotlib 1.5.3 to version 2.0.2
This stopped my code from crashing and my basic testing against older matplotlib version appears to produce the correct results.
I hope this does not have unintended consequences else where, though basemap was designed with the old integer division so I assume it is OK
Solution 2:
This behavior is the sequent of python3 integer division. Look for examples:
1) python3:
n=100
print (n/2, (n+1)/2)
Output: 50.0 50.5
2) For python 2.7 this code returns 50 50
Solutions:
1) manually update lines of basemap with division for python3.
You have to write for integer n: n//2
which is apply division from python2.
2) or run your program with python2.
Post a Comment for "Indexerror When Using Some Projections With Basemap And Contourf In Python 3.6.1"