简体   繁体   English

使用gridspec并排绘制多个Cartopy地图?

[英]Plotting multiple Cartopy maps side-by-side using gridspec?

The goal is to produce a divided figure with one large Orthographic map on the left and twelve smaller EqualEarth projections on the right.目标是生成一个分割图形,左侧有一个大的 Orthographic map,右侧有十二个较小的 EqualEarth 投影。 This will eventually be animated, filled with data, etc. For now, the smallest example is below:这最终将被动画化,填充数据等。现在,最小的示例如下:

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

fig = plt.figure(figsize=(16,8), constrained_layout=True)
gs = fig.add_gridspec(1, 2)

ax0 = fig.add_subplot(gs[0,0])
ax0 = plt.axes(projection=ccrs.Orthographic())
ax0.coastlines(resolution='110m')

nrows = 4
ncols = 3

for i in range(nrows*ncols):
    ax1 = fig.add_subplot(nrows, ncols, i+1, projection=ccrs.EqualEarth())
    ax1.set_global()
    ax1.coastlines()

This produces this result:这会产生以下结果:

实际结果

The preferred result would look like this:首选结果如下所示:

首选结果

How do I achieve this?我如何实现这一目标? It doesn't have to use gridspec, if there is a better way.如果有更好的方法,它不必使用 gridspec。

EDIT: success with the following code:编辑:使用以下代码成功:

fig = plt.figure(figsize=(12, 5.5), constrained_layout=True)
gs0 = fig.add_gridspec(1, 2, width_ratios=[1, 2])

ax0 = fig.add_subplot(gs0[0], projection=ccrs.Orthographic())
ax0.coastlines()

gs01 = gs0[1].subgridspec(4, 3)

for a in range(4):
    for b in range(3):
        ax = fig.add_subplot(gs01[a, b], projection=ccrs.EqualEarth())

You basically want to do what is described here: https://matplotlib.org/tutorials/intermediate/gridspec.html#gridspec-using-subplotspec你基本上想做这里描述的事情: https://matplotlib.org/tutorials/intermediate/gridspec.html#gridspec-using-subplotspec

I didn't bother to download cartopy, but you get the idea...我没有费心去下载cartopy,但你明白了......


fig = plt.figure(constrained_layout=True)
gs0 = fig.add_gridspec(1, 2, width_ratios=[1, 2])

ax0 = fig.add_subplot(gs0[0])

gs01 = gs0[1].subgridspec(4, 3)

for a in range(4):
    for b in range(3):
       ax = fig.add_subplot(gs01[a, b])

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM