Thursday, August 3, 2017

Python draw map

Shapefile could be found here.

#conda install -c conda-forge basemap=1.0.8.dev0
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots(figsize=(8,8), dpi=120)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['bottom'].set_visible(False)

#lat and lon for Delhi lat_0=28.7041, lon_0=77.1025
#for projection lat_0, and lon_0 should be given

map = Basemap(projection='mill', lat_0=0, lon_0=0, #projection = 'mill', 'ortho'
              resolution='l') 
map.drawcoastlines(linewidth=0.1)
map.drawcountries(linewidth=0.1)
map.drawstates(linewidth=0.05)
map.etopo()
map.drawmeridians(np.arange(0, 360, 30), linestyle='--', linewidth=0.5)
map.drawparallels(np.arange(-90, 90, 30), linestyle='--', linewidth=0.5)

shp_info = map.readshapefile(r'F:\Python\StatPlanet_India_Hindi\map\map', 
#                             name='comarques',
                             name='zone',
                             linewidth=0.1)

x, y = map(77.1025, 28.7041)

map.plot(x, y, marker='o', color='m', markersize=0.1)
plt.text(x, y, "Delhi", 
         horizontalalignment='center', 
         verticalalignment='top',
         size=3)
plt.show()

No comments:

Post a Comment