Cartopy figsize 不会改变地图的实际大小

Cartopy figsize does not change the actual size of the map

如何在使用cartoopy时改变图形的宽度和高度。 figsize 仅更改图形周围的白色 space,而不更改图形本身。有任何想法吗。

import cartopy.crs as ccrs 
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

def main():
    fig = plt.figure(figsize=(10,10))
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
    ax.set_extent([-20, 60, -40, 45], crs=ccrs.PlateCarree())

    ax.add_feature(cfeature.LAND)
    ax.add_feature(cfeature.OCEAN)
    ax.add_feature(cfeature.COASTLINE)
    ax.add_feature(cfeature.BORDERS, linestyle=':')
    ax.add_feature(cfeature.LAKES, alpha=0.5)
    ax.add_feature(cfeature.RIVERS)

    plt.show()

if __name__ == '__main__':
    main()

找到此代码here

地图的大小只能通过set_extent()方法定义其范围。更改 figsize 只会影响地图轴周围的白框。

编辑

如果您想放大地图而不改变其范围,我只看到一个选项:更改投影。这里有一些例子:

如您所见,一些投影会倾向于增加高度,而另一些会显得更宽。您无法完全控制地图的 width/height 比例,但您仍然可以尝试查看某些投影是否更适合您。

您可以在 https://scitools.org.uk/cartopy/docs/v0.15/crs/projections.html 找到投影列表。

这是生成第一张图片的代码:

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(3, 3))

ax = fig.add_subplot(1, 1, 1, projection=ccrs.LambertCylindrical())
ax.set_extent([-20, 60, -40, 45])
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.BORDERS, linestyle=':')
ax.add_feature(cfeature.LAKES, alpha=0.5)
ax.add_feature(cfeature.RIVERS)
ax.set_title('LambertCylindrical')

plt.savefig('LambertCylindrical.png', dpi=100)