在matplotlib中,除了为整个图形设置标题和为每个单独的绘图设置标题之外,还可以为每一行子图设置一个单独的标题吗?这将与下图中的橙色文本相对应。

如果没有,你如何解决这个问题?在左边创建一个单独的空子图列,并用橙色文本填充它们?
我知道使用text()或annotate()手动定位每个标题是可能的,但这通常需要大量的调整,而且我有很多子图。有更顺畅的解决方案吗?
发布于 2021-07-01 11:15:18
新的matplotlib 3.4.0
行标题现在可以实现为子图虚拟标题。
新的子图形特性允许使用本地化的艺术家(例如,彩色条和虚拟标题)在图形中创建虚拟图形,而只适用于每个子图形。 有关更多细节,请参见如何绘制子图。
如何复制OP的参考数字:
Figure.subfigures (最直截了当)
创建3x1 fig.subfigures,其中每个subfig都有自己的1x3 subfig.subplots和subfig.suptitle:
图= plt.figure(constrained_layout=True) fig.suptitle(“图标题”)# create 3x1子图,子图= fig.subfigures(nrows=3,ncols=1)用于行,子图中枚举(子图):subfig.suptitle(f‘子图标题{ row }') #创建1x3子图,每个子图axs = subfig.subplots(nrows=1,ncols=3),ax in枚举(Axs):ax.plot() ax.set_title(f’‘Plot{ col })Figure.add_subfigure (放到现有的subplots上)
如果您已经有了3x1 plt.subplots,那么add_subfigure就进入底层gridspec。同样,每个subfig都将得到自己的1x3 subfig.subplots和subfig.suptitlecreate 3x1子图--图图,axs = plt.subplots(nrows=3,ncols=1,constrained_layout=True) fig.suptitle(“数字标题”)# ax中ax的清晰子图: ax.remove(),每子图添加子图= axs.get_subplotspec().get_gridspec()子图=axs.get_subplotspec().get_gridspec()子图= fig.add_subfigure( gs ),枚举(子图)中的子图(子图):subfig.suptitle(f‘子图标题{row}') # create 1x3每个子图axs = subfig.subplots(nrows=1,ncols=3)用于col,axs(Axs):ax.plot() ax.set_title(f’‘Plot {col}')这两个示例的输出(在某些样式之后):

发布于 2014-12-11 19:34:12
一个想法是创造三个“大的子情节”,给他们每一个标题,并使他们看不见。在此基础上,您可以创建由较小的子图组成的矩阵。
该解决方案完全基于这个职位,只是更多地关注实际删除背景子图。

import matplotlib.pyplot as plt
fig, big_axes = plt.subplots( figsize=(15.0, 15.0) , nrows=3, ncols=1, sharey=True)
for row, big_ax in enumerate(big_axes, start=1):
big_ax.set_title("Subplot row %s \n" % row, fontsize=16)
# Turn off axis lines and ticks of the big subplot
# obs alpha is 0 in RGBA string!
big_ax.tick_params(labelcolor=(1.,1.,1., 0.0), top='off', bottom='off', left='off', right='off')
# removes the white frame
big_ax._frameon = False
for i in range(1,10):
ax = fig.add_subplot(3,3,i)
ax.set_title('Plot title ' + str(i))
fig.set_facecolor('w')
plt.tight_layout()
plt.show()发布于 2020-11-11 17:50:44
另一个简单的欺骗是将中间列的标题命名为subplot row XX\n\nPlot title No.YY
https://stackoverflow.com/questions/27426668
复制相似问题