【发布时间】:2022-01-02 15:37:00
【问题描述】:
我正在尝试从底图切换到 cartopy,但在绘制简单的 shapefile 时遇到了一些困难。
使用底图我可以得到这个
代码:
from mpl_toolkits.basemap import Basemap
# define map extent
lllat=1.1497
urlat=1.5133
lllon=103.5822
urlon=104.1579
# Set up Basemap instance
m = Basemap(
projection = 'merc',
llcrnrlon = lllon, llcrnrlat = lllat, urcrnrlon = urlon, urcrnrlat = urlat,
resolution='h')
shp_info = m.readshapefile('singapore_shapefile',
'singapore',
drawbounds=True)
import cartopy.crs as ccrs
import cartopy.io.shapereader as shpreader
from cartopy.feature import ShapelyFeature
# define map extent
lllat=1.1497
urlat=1.5133
lllon=103.5822
urlon=104.1579
# Set up cartopy instance
m = ccrs.Mercator()
ax = plt.axes(projection=m)
plt.gcf().set_size_inches(20, 10)
reader = shpreader.Reader("singapore_shapefile")
shape_feature = ShapelyFeature(reader.geometries(), m, facecolor="w",
edgecolor='black', lw=1)
ax.add_feature(shape_feature)
plt.savefig("test.png")
谁能指出我正确的方向?
形状文件:https://drive.google.com/file/d/1suB-VD65bmwesJo01mAvVUolRReWUkdV/view?usp=sharing
【问题讨论】:
标签: python matplotlib-basemap cartopy