在带有子直方图的pandas hist()图中,如何为x和y轴插入标题以及整体标题? [英] In a pandas hist () plot with sub-histograms, how to insert titles for the x and y axes, and overall title?

查看:288
本文介绍了在带有子直方图的pandas hist()图中,如何为x和y轴插入标题以及整体标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using the pandas hist() method with the 'by' option, specifically:

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

此命令生成此图:

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

How do I add titles for respectively the x and y axes on each of the sub-histograms, or alternatively, overall? Also, how to insert an overall title for the plot?

我尝试了以下操作,但没有通过(错误为AttributeError: 'numpy.ndarray' object has no attribute 'set_ylabel'"):

I tried the following, but it does not go through (with error "AttributeError: 'numpy.ndarray' object has no attribute 'set_ylabel'"):

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

非常感谢您的任何建议

推荐答案

您实际上得到的是对象类型的numpy数组,其中包含AxesSubplot实例的元素.试试

What you actually get is an object-type numpy array with elements in it that are the AxesSubplot instances. Try

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

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

EDIT : To change the format of ticks, use a Formatter:

from matplotlib.ticker import FormatStrFormatter

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

可以在此处找到有关刻度定位和格式的文档.

The documentation on tick locating and formatting can be found here.

这篇关于在带有子直方图的pandas hist()图中,如何为x和y轴插入标题以及整体标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆