Draw maps

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 http://www.diva-gis.org/gdata

(Don’t forget Taiwan)

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'CHN_adm/CHN_adm1', 'states', drawbounds=True)
m.readshapefile(r'TWN_adm/TWN_adm1', 'states', drawbounds=True)

ax = plot.gca()

plot.show

Well… It looks not so good.

It can be modified…

Chinese map with province (modified)

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

plot.figure(figsize=(14,6))
m = Basemap(
    llcrnrlon=77,
    llcrnrlat=14,
    urcrnrlon=140,
    urcrnrlat=51,
    projection='lcc', 
    lat_1=33, 
    lat_2=45, 
    lon_0=100
)

m.readshapefile(r'CHN_adm/CHN_adm1', 'states', drawbounds=True)
m.readshapefile(r'TWN_adm/TWN_adm1', 'states', drawbounds=True)

ax = plot.gca()

plot.show() 

Better.

Next, we are going to color the map to make it more beautiful!

https://dyingdown.github.io/2020/02/13/Draw-map-with-Color/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值