Basemap with Python 3.5 Anaconda on Windows

Prikers picture Prikers · Mar 1, 2016 · Viewed 44.1k times · Source

I use Python 3.5 with latest version of Anaconda on Windows (64 bit). I wanted to install Basemap using conda install basemap. Apparently there is a conflict between Python 3 and basemap. After some googling indeed I found that basemap is not supported on Python 3 for Windows users (ex: https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/TjAwi3ilQaU).

For obvious reasons I do not want to downgrade to Python 2. What would then be the simplest alternative solution?

  • Is there an alternative package similar to basemap for ploting maps, etc.?
  • Should I use a second environment which uses Python 2 and basemap? I have never done that but it seems possible (http://conda.pydata.org/docs/py2or3.html). Is it "safe"? Should I install again all the other packages (matplotlib, numpy, etc.) on the second environment?

Thanks in advance for the help and advice.

Answer

Kalin Stoyanov picture Kalin Stoyanov · Mar 3, 2017

Referring to the answer of Solly, I have Windows 10, python 3.5.3, Anaconda 64bit, in the Anaconda prompt I entered:

conda install -c conda-forge basemap=1.0.8.dev0
conda install -c conda-forge basemap-data-hires

then the code, taken from Python for Data Science for Dummies, page 193 (Plotting geographical data worked just fine. I wanted to add just a comment to the Solly's answer, but I don't have enough credits to do so. The code is:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap

austin = (-97.75, 30.25)
hawaii = (-157.8, 21.3)
washington = (-77.01, 38.90)
chicago = (-87.68, 41.83)
losangeles = (-118.25, 34.05)

m = Basemap(projection = 'merc', llcrnrlat=10, urcrnrlat=50,
        llcrnrlon=-160, urcrnrlon=-60)

m.drawcoastlines()
m.fillcontinents (color='lightgray', lake_color='lightblue')
m.drawparallels(np.arange(-90.,91.,30.))
m.drawmeridians(np.arange(-180.,181.,60.))
m.drawmapboundary(fill_color='aqua')

m.drawcounties()

x, y = m(*zip(*[hawaii, austin, washington, chicago, losangeles]))
m.plot(x,y, marker ='o', markersize=6, markerfacecolor='red', linewidth=0)

plt.title('Mercator Projection')
plt.show()