[英]Add labels for X-axis in pandas.DataFrame.plot
I have a dataframe that contains a column c
of ones and zeros.我有一个 dataframe 包含一列c
的一和零。 I want to plot the histogram for this column.我想 plot 此列的直方图。 I tried the following:我尝试了以下方法:
df.c.plot(kind='hist', weights = np.ones_like(df.index)/ len(df.index), title='Percentage', grid=True)
The result is a plot with two bars;结果是一个带有两个条的 plot; one for the zero value and one for the one value.一个代表零值,一个代表一值。 How to add labels for these two bars, say on the x-axis?如何为这两个条添加标签,比如在 x 轴上? Instead of using weights
, is there another way to present the percentage values?除了使用weights
,还有其他方法可以显示百分比值吗?
I have a dataframe that contains a column c
of ones and zeros.我有一个 dataframe 包含一列c
的一和零。 I want to plot the histogram for this column.我想 plot 此列的直方图。 I tried the following:我尝试了以下方法:
df.c.plot(kind='hist', weights = np.ones_like(df.index)/ len(df.index), title='Percentage', grid=True)
The result is a plot with two bars;结果是一个带有两个条的 plot; one for the zero value and one for the one value.一个代表零值,一个代表一值。 How to add labels for these two bars, say on the x-axis?如何为这两个条添加标签,比如在 x 轴上? Instead of using weights
, is there another way to present the percentage values?除了使用weights
,还有其他方法可以显示百分比值吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.