我正在寻找有关如何在由 pandas df.hist() 命令生成的直方图集合顶部显示标题的建议。例如,在下面代码生成的直方图块中,我想在图的顶部放置一个通用标题(例如“我的直方图集合”):
data = DataFrame(np.random.randn(500).reshape(100,5), columns=list('abcde'))
axes = data.hist(sharey=True, sharex=True)
我尝试在 hist 命令中使用title关键字(即 title='My collection of histogram plots'),但这不起作用。
通过将文本添加到其中一个轴,以下代码确实有效(在 ipython 笔记本中),但有点杂乱无章。
axes[0,1].text(0.5, 1.4,'My collection of histogram plots', horizontalalignment='center',
verticalalignment='center', transform=axes[0,1].transAxes)
有没有更好的办法?