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
~
来源:CSDN
作者:Wolf Baby
链接:https://blog.csdn.net/yaoo_o/article/details/104246455