是否可能有多个字幕?

问题描述 投票:0回答:1

如果我有一个带有子图的matplotlib图形,是否可以有多个suptitle? (Kind of like the loc='center', loc='left', and loc='right' arguments for a regular title)。

在下面的示例中,suptitle的多个实例被覆盖,并且图形上仅显示最后一个字幕。

import matplotlib.pyplot as plt
fig, (ax1, ax2) = plt.subplots(1,2)

plt.suptitle('center title')
plt.suptitle('right title', x=.8)
plt.suptitle('left title', x=.2)

enter image description here

python matplotlib
1个回答
0
投票

我想出的最好的解决方案是在绘图中添加文本,并根据图形的坐标并使用参数transform=fig.transFigure来调整位置。

import matplotlib.pyplot as plt
fig, (ax1, ax2) = plt.subplots(1,2)

plt.text(.5, 1, 'center title', transform=fig.transFigure, horizontalalignment='center')
plt.text(.8, 1, 'right title', transform=fig.transFigure, horizontalalignment='center')
plt.text(.2, 1, 'left title', transform=fig.transFigure, horizontalalignment='center')

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.