如果使用“by”参数,如何在 Series 上使用 pandas hist 函数创建的直方图添加标题?
对于简单的直方图,不存在任何问题。因此,以下工作完美:
In [115]: runELMLearning.utime.hist()
Out[115]: <matplotlib.axes.AxesSubplot at 0x20aaa590>
In [116]: plt.title("fooo")
Out[116]: <matplotlib.text.Text at 0x228b8550>
但是,当使用 by 子句时,这不再起作用:
In [117]: runELMLearning.utime.hist(by=runELMLearning.state)
Out[117]:
array([[Axes(0.1,0.763636;0.222222x0.136364),
Axes(0.388889,0.763636;0.222222x0.136364),
Axes(0.677778,0.763636;0.222222x0.136364)],
[Axes(0.1,0.559091;0.222222x0.136364),
Axes(0.388889,0.559091;0.222222x0.136364),
Axes(0.677778,0.559091;0.222222x0.136364)],
[Axes(0.1,0.354545;0.222222x0.136364),
Axes(0.388889,0.354545;0.222222x0.136364),
Axes(0.677778,0.354545;0.222222x0.136364)],
[Axes(0.1,0.15;0.222222x0.136364),
Axes(0.388889,0.15;0.222222x0.136364),
Axes(0.677778,0.15;0.222222x0.136364)]], dtype=object)
In [118]: plt.title("fooo")
Out[118]: <matplotlib.text.Text at 0x13612b10>
即使它没有表示任何错误,标题也会被默默地忽略。
我做的另一个奇怪的观察是,当我先创建一个图形,然后使用 hist 函数时,在 by 参数的情况下,第一个图形被忽略并且 hist 函数创建一个新的图形,我找不到的 gca matplotlib。对于简单的直方图再次没有问题。