python - 在 python 中构建一个直方图,其中一列作为 x 轴,三列作为 y 轴
问题描述
我有以下数据
method,RequirementT,RequirementN,RequirementU
1,1,7,0
2,0,0,8
3,2,6,0
4,1,7,0
5,2,6,0
6,2,6,0
这是我的完整数据的链接 https://drive.google.com/file/d/1aBRy2uf34kjWQAo8nUDMnuAEHPR4XBMD/view?usp=sharing
我想在 python 中构建一个直方图,使 x 轴对应于我的数据(方法)的第一列,而其他三列(RequirementT、RequirementN、RequirementU)在 y 轴上表示。我希望图表采用直方图的形式。
我已经尝试过df.plot.bar(x='method', y=['RequirementT', 'RequirementN', 'RequirementU'])
,这给了我以下输出,这显然是错误的,完全不可读,我不知道为什么 x 轴周围有这些粗黑线
解决方案
这对我有用:
df.plot.bar(x='method', y=['RequirementT', 'RequirementN', 'RequirementU'])
您在寻找分布图吗?尝试这个:
import seaborn as sns
import matplotlib.pyplot as plt
df = df.set_index('method', drop=True)
sns.distplot(df.iloc[:, 0], bins=10) # just use .loc and insert your 3 columns instead of 0, 1, 2
sns.distplot(df.iloc[:, 1], bins=10)
sns.distplot(df.iloc[:, 2], bins=10)
plt.show()
推荐阅读
- visual-studio-code - 将光标(插入符号)移动到当前视图
- r - 循环遍历变量并进行置换意味着每个变量的差异测试
- reactjs - 我们如何配置 dotnet core react 应用程序以使用多条目?
- c# - 在编写 DefaultTrackableEventHandler.cs 脚本时,如何修复“成员修饰符“受保护”必须位于成员类型和名称之前
- c - C列表多线程同步
- java - java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Handler
- python - 如何使用for循环使用python脚本将值1-100插入redis?
- python - 将熊猫数据框的日期与当前日期进行比较
- docker - 如何从 docker 取消设置环境变量?
- docker - 仅在使用 Dockerfile 进行生产时,如何复制文件?