将标题添加到 pandas 历史地块集合中 [英] add title to collection of pandas hist plots
问题描述
我正在寻找有关如何在熊猫df.hist()命令生成的直方图图的顶部显示标题的建议.例如,在下面的代码生成的直方图图形块中,我想在图形的顶部放置一个通用标题(例如我的直方图集合")
I'm looking for advice on how to show a title at the top of a collection of histogram plots that have been generated by a pandas df.hist() command. For instance, in the histogram figure block generated by the code below I'd like to place a general title (e.g. 'My collection of histogram plots') at the top of the figure:
data = DataFrame(np.random.randn(500).reshape(100,5), columns=list('abcde'))
axes = data.hist(sharey=True, sharex=True)
我尝试在hist命令中使用 title 关键字(即title =我的直方图图集"),但这没用.
I've tried using the title keyword in the hist command (i.e. title='My collection of histogram plots'), but that didn't work.
以下代码可以通过在其中一个轴上添加文本来工作(在ipython笔记本中),但有点麻烦.
The following code does work (in an ipython notebook) by adding text to one of the axes, but is a bit of a kludge.
axes[0,1].text(0.5, 1.4,'My collection of histogram plots', horizontalalignment='center',
verticalalignment='center', transform=axes[0,1].transAxes)
有更好的方法吗?
推荐答案
您可以使用suptitle()
:
import pylab as pl
from pandas import *
data = DataFrame(np.random.randn(500).reshape(100,5), columns=list('abcde'))
axes = data.hist(sharey=True, sharex=True)
pl.suptitle("This is Figure title")
这篇关于将标题添加到 pandas 历史地块集合中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!