如果我有一个带有子图的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)
我想出的最好的解决方案是在绘图中添加文本,并根据图形的坐标并使用参数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')