繁体   English   中英

是否可以有多个字幕?

[英]Is it possible to have more than one suptitle?

如果我有一个带有子图的 matplotlib 图,是否可以有多个suptitle 有点像常规标题的 loc='center'、loc='left' 和 loc='right' 参数)。

在下面的示例中, suptitle的多个实例被覆盖,图中仅显示最后一个 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')

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM