除了another Q&A,我正在绘制地球上的非洲大陆各国的地图:
import cartopy
import cartopy.crs as ccrs
from matplotlib import pyplot as plt
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
africa = world[(world['continent'] == 'Africa')]
latlon_proj = ccrs.PlateCarree()
axis_proj = ccrs.Mollweide()
ax = plt.axes(projection=axis_proj)
ax.stock_img()
for ea in africa['geometry']:
feat = cartopy.feature.ShapelyFeature(
[ea],
latlon_proj,
facecolor="lime",
edgecolor='black',
lw=0.2
)
ax.add_feature(feat)
plt.show()

然而,当我把latlon_proj和axis_proj改成ccrs.Orthographic()时,非洲大陆消失了:
import cartopy
import cartopy.crs as ccrs
from matplotlib import pyplot as plt
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
africa = world[(world['continent'] == 'Africa')]
latlon_proj = ccrs.Orthographic()
axis_proj = ccrs.Orthographic()
ax = plt.axes(projection=axis_proj)
ax.stock_img()
for ea in africa['geometry']:
feat = cartopy.feature.ShapelyFeature(
[ea],
latlon_proj,
facecolor="lime",
edgecolor='black',
lw=0.2
)
ax.add_feature(feat)
plt.show()

我怎样才能保持非洲大陆在改变CCRS的时候?
发布于 2021-08-30 09:20:11
在代码中使用CRS是错误的。这是它的正确版本。
import cartopy
import cartopy.crs as ccrs
from matplotlib import pyplot as plt
import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
africa = world[(world['continent'] == 'Africa')]
latlon_proj = ccrs.PlateCarree() ## The correct CRS
axis_proj = ccrs.Orthographic()
ax = plt.axes(projection=axis_proj)
ax.stock_img()
for ea in africa['geometry']:
feat = cartopy.feature.ShapelyFeature(
[ea],
latlon_proj,
facecolor="lime",
edgecolor='black',
lw=0.2
)
ax.add_feature(feat)
plt.show()

https://stackoverflow.com/questions/68981605
复制相似问题