【发布时间】:2020-06-21 19:35:07
【问题描述】:
我在 matplotlib 中使用 GridSpec 来尝试生成以下图:
但是,我无法在所需位置添加标题,这些位置位于每两列的顶部中心。以下代码在无标题上方创建图:
fig = plt.figure(constrained_layout=True)
gs = fig.add_gridspec(2, 6)
for i in range(0, 6, 2):
fig.add_subplot(gs[:, i])
fig.add_subplot(gs[0, i + 1])
fig.add_subplot(gs[1, i + 1])
添加以下两行会创建标题,但也会在其他图形上方创建一个图形:
title = fig.add_subplot(gs[:, i:i + 2])
title.set_title(f'title #{i}')
我必须如何更改给定的代码才能获得上述所需的结果?有没有办法隐藏新的数字?有没有办法在没有数字的情况下设置标题/文本?
【问题讨论】:
-
这是我们希望在 3.4 中拥有的东西。
-
新功能的名称是什么?
-
这里讨论的子面板功能:github.com/matplotlib/matplotlib/pull/17437
标签: python matplotlib subplot