gpt4 book ai didi

python - 为 pandas hist plots 集合添加标题

转载 作者:IT老高 更新时间:2023-10-28 20:50:32 58 4
gpt4 key购买 nike

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

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)

有没有更好的办法?

最佳答案

对于较新的 Pandas 版本,如果有人感兴趣,这里有一个稍微不同的解决方案,仅适用于 Pandas:

ax = data.plot(kind='hist',subplots=True,sharex=True,sharey=True,title='My title')

关于python - 为 pandas hist plots 集合添加标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19614400/

58 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com