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

标签 python matplotlib pandas

我正在使用带有“by”选项的 pandas hist() 方法,特别是:

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

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

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

我尝试了以下方法,但它没有通过(错误“AttributeError:‘numpy.ndarray’对象没有属性‘set_ylabel’”):

histos.set_ylabel('Fréquence')
histos.set_xlabel('Variation prix suggérée, en %')

非常感谢任何建议

最佳答案

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

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

编辑: 要更改刻度的格式,请使用 Formatter:

from matplotlib.ticker import FormatStrFormatter

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

可以找到有关刻度定位和格式化的文档 here .

关于python - 在带有子直方图的 Pandas hist () 图中,如何插入 x 轴和 y 轴的标题以及整体标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24913661/

相关文章:

python - Python中有没有办法计算多条曲线之间的重叠面积?

python - 将 C 数组移植到 Python

python - 在 TensorFlow 中计算交叉熵

python - 如何使用 matplotlib 和 pandas 绘制日期时间与值的线性趋势线?

python - 如何对不同系列中具有特定属性的元素进行计数

python - pandas 多索引列样式器

python - 无法将数据帧转换为 CSV

python - 如何在条形图matplotlib中添加垂直居中的标签

python - 如何更改使用 Matplotlib 绘制的图形的大小?

python - 如何在条件匹配三行的情况下迭代pandas数据框中的选定行?