our*_*nos 0 python gis matplotlib cartopy
我想制作一个专注于欧洲的兰伯特圆锥图。我可以执行以下操作:
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
proj = ccrs.LambertConformal(central_longitude=20.0, central_latitude=45.0, cutoff=30)
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111, projection=proj)
ax.coastlines(resolution='110m')
plt.show()
Run Code Online (Sandbox Code Playgroud)
然而,这向东部和西部延伸太多了。我想将其缩小到 10W 到 40E 之间。如果我添加一条线ax.set_extent([-10,40,30,90], crs=ccrs.PlateCarree()),我就会失去上面绘图的圆锥形“外观”:
如何正确减小 Cartopy 的 LambertConformal 中的纵向范围,同时仍然保持圆锥曲线的外观?我可以给出经度边距并在两条经线之间调整第一个图形,而不是将其放入此矩形中吗?我想象两条经线之间有一个三角形,在低纬度界限有一个拱形。
这是你想要的?
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import matplotlib.path as mpath
ax = plt.axes(projection=ccrs.LambertConformal(central_longitude=20.0, central_latitude=45.0))
ax.gridlines()
ax.coastlines(resolution='110m')
# Lon and Lat Boundaries
xlim = [-10, 40]
ylim = [30, 90]
lower_space = 10 # this needs to be manually increased if the lower arched is cut off by changing lon and lat lims
rect = mpath.Path([[xlim[0], ylim[0]],
[xlim[1], ylim[0]],
[xlim[1], ylim[1]],
[xlim[0], ylim[1]],
[xlim[0], ylim[0]],
]).interpolated(20)
proj_to_data = ccrs.PlateCarree()._as_mpl_transform(ax) - ax.transData
rect_in_target = proj_to_data.transform_path(rect)
ax.set_boundary(rect_in_target)
ax.set_extent([xlim[0], xlim[1], ylim[0] - lower_space, ylim[1]])
Run Code Online (Sandbox Code Playgroud)
改编自此示例。
输出: