在pandas hist()图中,如何插入x轴和y轴的标题以及总标题?

2024-10-01 11:41:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我将pandas hist()方法与“by”选项一起使用,特别是:

histos=data_ok._DiffPricePercent.hist(by=input_data._Category, sharex=True, sharey=True )

此命令生成以下绘图: This is the plot I am getting

如何分别为每个次柱状图上的x和y轴添加标题,或者总体上?另外,如何插入情节的总标题?在

我尝试了以下方法,但它没有通过(错误为“AttributeError:”努比·恩达雷'对象没有属性'set\'ylabel'):

^{pr2}$

非常感谢您的任何建议


Tags: 方法true标题pandasinputdataby选项
2条回答

pandas数据帧上的.plot或.hist可能会编写一个给定大小的numpy数组。在

在子地块级别设置属性的一种方法是(假设熊猫图输出的numpy数组plt是2D):

    for (x,y), value in numpy.ndenumerate(plt)
      plt[x,y].set_xlabel(...)
      plt[x,y].set_xticks([...])

等等。在

实际得到的是一个对象类型numpy数组,其中的元素是axesssubplot实例。试试看

histos[0].set_xlabel('My x label 1')
histos[1].set_xlabel('My x label 2')

编辑: 要更改刻度的格式,请使用格式化程序:

^{pr2}$

关于记号定位和格式化的文档可以在here找到。在

相关问题 更多 >