python - 如何创建一个 3X5 子图网格,其中第一列和第一行的前 2 个单元格合并为一个大子图?
问题描述
如何创建一个最初有 15 个子图的子图网格,但其中 4 个子图合并到一个更大的子图中,这样实际上只有 12 个子图:11 个较小的子图和一个较大的子图。我在这里附上了一张我用 Photoshop 创建的图像: 3x5 子图网格,左上角有一个更大的子图
解决方案
import matplotlib.pyplot as plt
import numpy as np
from itertools import product
# create a figure, use the best avalable layout and add a gridspec
fig = plt.figure(constrained_layout=True)
gs = fig.add_gridspec(3, 5)
# three actions
# create a larger subplot that spans rows 0 to 2 (that is, 0 and 1)
# and columns 0 to 2 (again that is 0 and 1)
ax_left_top = fig.add_subplot(gs[0:2,0:2])
# now the axes on the right, we put them in a list,
# the rows are 0,1, the columns 2,3,4
axes_right = [fig.add_subplot(gs[r,c]) for r,c in product((0,1),(2,3,4))]
# finally a list containing the axes on the bottom, the row #2
# and all the columns
axes_bottom = [fig.add_subplot(gs[2,c]) for c in (0, 1, 2, 3, 4)]
# label the axes for your reference
ax_left_top.annotate('ax_left_top', (.1,.5))
for n, ax in enumerate(axes_right):
ax.annotate('axes_right[%d]'%n, (0.3,0.5))
for n, ax in enumerate(axes_bottom):
ax.annotate('axes_bottom[%d]'%n, (0.2,0.5))
推荐阅读
- kubernetes - 带有 admission webhook 的 kubeadm
- twitter-bootstrap - 角材料,引导
- generator - 如何使用基于 Promise 的普通代码中的生成器函数?
- php - 使用 Skrill 插件将 WC_Payment_Gateway 描述添加到 Woocommerce 选项支付
- javascript - Vuejs从上到下添加项目
- rust - Rust 中的 Arc 中的临时生命周期
- python - 仅当字符不在括号中时才替换字符
- python - Tensorflow:如何在约束下最小化
- python - 使用python抓取AJAX电子商务网站
- ionic3 - 与 Ionic 一起使用时,电子无法找到图像