简体   繁体   English

如何标记按熊猫分组的箱线图?

[英]How to label a grouped by pandas boxplot?

I have a dataframe that I want to boxplot using groupby, The x-axis is labeled but the y-axis is not.我有一个数据框,我想使用 groupby 进行箱线图,x 轴已标记,但 y 轴未标记。 How do I label the y-axis?如何标记 y 轴?

import pandas as pd, numpy as np

df = pd.DataFrame(np.random.rand(12,2), columns=['Apples', 'Oranges'] )
df['Categories'] = pd.Series(list('AAAABBBBCCCC'))
df.boxplot(by='Categories')
plt.ylabel("LABELLL")

I'd like the label 'LABELL' to be part of the plot, on the y axis.我希望标签“LABELL”成为图的一部分,位于 y 轴上。 How do I do that?我怎么做? 输出

ax = df.boxplot(by='Categories')
ax[0].set_ylabel("LABELLL")

df.boxplot returns a numpy.ndarray of matplotlib.axes.Axes objects. df.boxplot返回一个matplotlib.axes.Axes对象的numpy.ndarray You can then set the ylabel on the first one.然后,您可以在第一个上设置 ylabel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM