pandas :分类数据的多个直方图 [英] Pandas: multiple histograms of categorical data
本文介绍了 pandas :分类数据的多个直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下数据框:
Type Cat1 Cat2 Cat3
0 A 0.384000 0.393000 0.458000
1 B 0.603337 0.381470 0.299773
2 C 0.585797 0.452570 0.317607
3 D 0.324715 0.765212 0.717755
我想生成三个直方图,每个猫"一个.每个直方图都必须在底部直方图上以x标签的形式显示每个类型"(例如类别)的值.
I want to produce three histograms, one for each "Cat". Each histogram must show the values for each "Type" (e.g., the categories) as x labels on the bottom histogram.
我一直在尝试使用df.plot(kind='hist')
来执行此操作,但无济于事:
I have been trying to do this using df.plot(kind='hist')
but to no avail:
ax=df.plot(kind='hist',subplots=True,layout=(3,1),title='My title',color='orange',grid=True,legend=False)
但是我看到了:
- x轴不显示四种类型,而只是一堆数字
- y轴的范围是0到4,而它的范围必须是0到1(这些是频率)
- 每个子图中仅显示一个条形图
我在做什么错了?
错误的绘画:
推荐答案
IIUC:
您不需要直方图,只需要条形图.
IIUC:
you don't want a histogram, you just want a bar plot.
df.set_index('Type').plot.bar(subplots=True, legend=False)
假设import matplotlib.pyplot as plt
axes = df.set_index('Type').plot.bar(subplots=True, legend=False)
plt.subplots_adjust(hspace=0.35)
这篇关于 pandas :分类数据的多个直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文