【发布时间】:2019-05-16 21:18:01
【问题描述】:
我正在尝试绘制以下数据
+-----------+------+------+
| Duration | Code | Seq. |
+-----------+------+------+
| 116.15 | 65 | 1 |
| 120.45 | 65 | 1 |
| 118.92 | 65 | 1 |
| 7.02 | 66 | 1 |
| 73.93 | 66 | 2 |
| 117.53 | 66 | 1 |
| 4.4 | 66 | 2 |
| 111.03 | 66 | 1 |
| 4.35 | 66 | 1 |
+-----------+------+------+
我的代码如下:
x1 = df.loc[df.Code==65, 'Duration']
x2 = df.loc[df.Code==66, 'Duration']
kwargs = dict(alpha=0.5, bins=10)
plt.hist(x1, **kwargs, color='k', label='Code 65')
plt.hist(x2, **kwargs, color='g', label='Code 66')
我理想地想要在 y 轴上是 Seq.对应于 x 轴上不同的 Durations 的数量。但是现在,我只得到了Durationson y 的计数。我该如何纠正这个问题?
【问题讨论】:
-
你的预期输出是什么
-
你想要这个:
df.groupby('Code').plot(y='Seq.', x='Duration', kind='bar', subplots=True)?你说hist所以可能不是。你的预期输出是什么。 -
我认为以上内容没有帮助。我希望看到直方图并计算 Seq 的数量。在每个持续时间(针对不同的代码)