将标题添加到熊猫历史地块集合中

发布于 2021-01-29 15:07:25

我正在寻找有关如何在熊猫df.hist()命令生成的直方图图的顶部显示标题的建议。例如,在下面的代码生成的直方图图形块中,我想在图形的顶部放置一个常规标题(例如“我的直方图集合”):

data = DataFrame(np.random.randn(500).reshape(100,5), columns=list('abcde'))
axes = data.hist(sharey=True, sharex=True)

我试过在hist命令中使用 title 关键字(即title =’我的直方图集合)’,但这没用。

以下代码通过在其中一个轴上添加文本来 实现 工作(在ipython笔记本中),但有点麻烦。

axes[0,1].text(0.5, 1.4,'My collection of histogram plots', horizontalalignment='center',
               verticalalignment='center', transform=axes[0,1].transAxes)

有没有更好的办法?

关注者
0
被浏览
84
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    您可以使用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")
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看