Python 在带有子直方图的pandas hist()绘图中,如何插入x轴和y轴的标题以及整体标题?

Python 在带有子直方图的pandas hist()绘图中,如何插入x轴和y轴的标题以及整体标题?,python,matplotlib,pandas,Python,Matplotlib,Pandas,我将pandas hist()方法与“by”选项一起使用,具体如下: histos=data_ok._DiffPricePercent.hist(by=input_data._Category, sharex=True, sharey=True ) 此命令生成以下绘图: 如何在每个子直方图上分别为x轴和y轴添加标题,或者总体添加标题?另外,如何为情节插入整体标题 我尝试了以下操作,但没有通过(错误为“AttributeError:'numpy.ndarray'对象没有属性'set_ylabe

我将pandas hist()方法与“by”选项一起使用,具体如下:

histos=data_ok._DiffPricePercent.hist(by=input_data._Category, sharex=True, sharey=True )
此命令生成以下绘图:

如何在每个子直方图上分别为x轴和y轴添加标题,或者总体添加标题?另外,如何为情节插入整体标题

我尝试了以下操作,但没有通过(错误为“AttributeError:'numpy.ndarray'对象没有属性'set_ylabel'):


非常感谢您提供的任何建议

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

histos[0].set_xlabel('My x label 1')
histos[1].set_xlabel('My x label 2')
编辑: 要更改记号的格式,请使用格式化程序:

from matplotlib.ticker import FormatStrFormatter

maj_frm = FormatStrFormatter('%.1f')
...
histos[0].xaxis.set_major_formatter(maj_frm)

可以找到有关记号定位和格式的文档。

.plot或.hist在pandas数据帧上可能会写入具有给定大小的numpy数组

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


等等。

hist
应该返回
对象,这些对象可用于设置标题和标签等内容。您使用的是什么版本的pandas?我使用的是pandas 0.14.0我收到错误“numpy.ndarray”对象没有属性“ylabel”
from matplotlib.ticker import FormatStrFormatter

maj_frm = FormatStrFormatter('%.1f')
...
histos[0].xaxis.set_major_formatter(maj_frm)
    for (x,y), value in numpy.ndenumerate(plt)
      plt[x,y].set_xlabel(...)
      plt[x,y].set_xticks([...])