Draw maps

 ̄綄美尐妖づ 提交于 2020-02-13 03:09:22

See this article on my own blog https://dyingdown.github.io/2020/02/06/Draw-map/

Preparation

Before you start to draw maps with python, you first need to install basemap and pyshp. Click here to see how to install basemap . And the following command to install pyshp

pip install pyshp --user

Draw maps

Since basemap is a plug-in in Python, so we first new a py file.

World map with coastlines

import matplotlib.pyplot as plot
from mpl_toolkits.basemap import Basemap

plot.figure(figsize=(16,8))
m = Basemap()
m.drawcoastlines()

plot.show()

World map with countries

import matplotlib.pyplot as plot
from mpl_toolkits.basemap import Basemap

plot.figure(figsize=(14,6))
m = Basemap()
m.drawcoastlines()
m.drawcountries(linewidth=1)
                
plot.show()

Chinese map board

import matplotlib.pyplot as plot
from mpl_toolkits.basemap import Basemap

plot.figure(figsize=(14,6))
m = Basemap(
    llcrnrlon=73.55770111084013,
    llcrnrlat=18.159305572509766,
    urcrnrlon=134.773925782502,
    urcrnrlat=53.56085968017586
)
m.drawcoastlines()
m.drawcountries(linewidth=1)

plot.show()

Chinese map with province

Download the provinces information here https://gadm.org/download_country_v3.html

import matplotlib.pyplot as plot
from mpl_toolkits.basemap import Basemap
from matplotlib.patches import Polygon

plot.figure(figsize=(14,6))
m = Basemap(
    llcrnrlon=73,
    llcrnrlat=18,
    urcrnrlon=134,
    urcrnrlat=53
)
m.drawcoastlines()
m.drawcountries(linewidth=1)

m.readshapefile(r'gadm36_CHN_shp/gadm36_CHN_1', 'states', drawbounds=True)
ax = plot.gca()

plot.show

Well… It looks not so good.

For further use, It will also use pandas and xlrd, so install them.

pip install pandas --user
pip install xlrd --user

~

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!