[英]cartopy shapefile turning out as a dot
我正在嘗試從底圖切換到 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
有兩點需要注意:
下面是修改后的代碼。
import cartopy.crs as ccrs
import cartopy.io.shapereader as shpreader
from cartopy.feature import ShapelyFeature
import matplotlib.pyplot as plt
# 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)
extent=[lllon,urlon,lllat,urlat]
ax.set_extent(extent)
reader = shpreader.Reader("singapore_shapefile")
shape_feature = ShapelyFeature(reader.geometries(), ccrs.PlateCarree(), facecolor="w",
edgecolor='black', lw=1)
ax.add_feature(shape_feature)
plt.savefig("singapore.png")
這是 output plot。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.