带有子图的多个标题(字幕) [英] Multiple titles (suptitle) with subplots

查看:64
本文介绍了带有子图的多个标题(字幕)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在3x3网格中有一系列9个子图,每个子图都有一个标题.我想为每一行添加一个标题.为此,我考虑使用 suptitle.问题是,如果我使用 3 个字幕,它们似乎被覆盖了,而且似乎只显示了最后一个.

I have a series of 9 subplots in a 3x3 grid, each subplot with a title. I want to add a title for each row. To do so I thought about using suptitle. The problem is if I use 3 suptitles they seems to be overwritten and only the last one seems to be shown.

这是我的基本代码:

fig, axes = plt.subplots(3,3,sharex='col', sharey='row')

for j in range(9):
    axes.flat[j].set_title('plot '+str(j))

plt1 = fig.suptitle("row 1",x=0.6,y=1.8,fontsize=18)
plt2 = fig.suptitle("row 2",x=0.6,y=1.2,fontsize=18)
plt3 = fig.suptitle("row 3",x=0.6,y=0.7,fontsize=18)
fig.subplots_adjust(right=1.1,top=1.6)

推荐答案

您可以修改标题和标签.检查以下根据您的代码改编的示例:

You can tinker with the titles and labels. Check the following example adapted from your code:

import matplotlib.pyplot as plt

fig, axes = plt.subplots(3,3,sharex='col', sharey='row')

counter = 0
for j in range(9):
    if j in [0,3,6]:
        axes.flat[j].set_ylabel('Row '+str(counter), rotation=0, size='large',labelpad=40)
        axes.flat[j].set_title('plot '+str(j))
        counter = counter + 1
    if j in [0,1,2]:
        axes.flat[j].set_title('Column '+str(j)+'\n\nplot '+str(j))
    else:
        axes.flat[j].set_title('plot '+str(j))

plt.show()

,结果为:

这篇关于带有子图的多个标题(字幕)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆