简体   繁体   English

在python中构建一个直方图,一列作为x轴,3列作为y轴

[英]build a histogram in python with one column as x axis and 3 columns as y axes

I have the following data我有以下数据

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

Here is a link to my full data https://drive.google.com/file/d/1aBRy2uf34kjWQAo8nUDMnuAEHPR4XBMD/view?usp=sharing这是我的完整数据的链接https://drive.google.com/file/d/1aBRy2uf34kjWQAo8nUDMnuAEHPR4XBMD/view?usp=sharing

I would like to built a histogram in python such that the x axis corresponds to the first column of my data (method) and the three other columns (RequirementT, RequirementN, RequirementU) are represented in the y axis.我想在 python 中构建一个直方图,使得 x 轴对应于我的数据(方法)的第一列,而其他三列(RequirementT、RequirementN、RequirementU)在 y 轴中表示。 I would like the graph to be under the form of a histogram.我希望图表采用直方图的形式。

I have tried df.plot.bar(x='method', y=['RequirementT', 'RequirementN', 'RequirementU']) and this gives me the following output which is obviously wrong, completely non readable and I don't know why there is these thick black lines around the x axis我试过df.plot.bar(x='method', y=['RequirementT', 'RequirementN', 'RequirementU'])这给了我以下输出,这显然是错误的,完全不可读,我不'不知道为什么 x 轴周围有这些粗黑线在此处输入图片说明

This works for me:这对我有用:

df.plot.bar(x='method', y=['RequirementT', 'RequirementN', 'RequirementU'])

在此处输入图片说明

Are you looking for a distribution plot?您在寻找分布图吗? Try this:尝试这个:

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()

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

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