import matplotlib.pyplot as plt
from cartopy import crs as ccrs, feature as cfeature
import cartopy.io.shapereader as shpreader
fig = plt.figure(figsize=(11, 11))
ax = plt.subplot(1, 1, 1, projection=ccrs.PlateCarree(central_longitude=0))
ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linewidth=1, color='gray', alpha=0.5, linestyle='--')
extent = (-180, 0, 0, 60) # Define the extent as (min_lon, max_lon, min_lat, max_lat)
ax.set_extent(extent)
ax.add_feature(cfeature.LAND , linewidth=0.5, edgecolor='black')
回报(正如我所期望的)
据我了解,程度
extent = (-180, 60, 0, 60)
应将范围限制在东经 60 度(红线所示),但事实并非如此:
我做错了什么?
您确定第一张图片按照您的预期返回吗?假设您指定最大纬度为 60°,地图范围可达 ~90°。
正如
set_extent
的文档字符串所提到的,如果您省略范围的投影,它将假定为大地测量版本。
因此,在您的情况下,您想要明确(无论如何这是一个很好的做法),并自己提供范围的预测。
例如使用与地图投影相同的方法:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
proj = ccrs.PlateCarree(central_longitude=0)
fig, ax = plt.subplots(figsize=(11, 11), subplot_kw=dict(projection=proj), facecolor="w")
ax.gridlines(draw_labels=True, lw=1, color='gray', alpha=0.5, linestyle='--')
ax.coastlines()
ax.set_extent((-180, 60, 0, 60), crs=proj)
如果您要更改最后一行,并明确提供大地投影:
ax.set_extent((-180, 60, 0, 60), crs=ccrs.Geodetic())
你会再次得到: