在带有子直方图的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?
问题描述
我正在使用带有 '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屋!