使用子图绘制Pandas groupby两列

时间:2016-03-18 13:29:39

标签: python matplotlib

我有四列,分别是CAID,PID,BitRate和timeStamp。 每个CAID可以具有一个或多个PID。 我想为每个CAID创建每个子图,并且在每个子图中PID代表多行,其中x是时间,y是比特率。 起初,我使用multiindex修复数据帧但失败了。 然后我尝试了组,给了我相同的子图。 我只是一个首发。谁能帮我?非常感谢。 以下是dataFrame,我的代码和结果的一部分。

DATA

CAID    PID   BitRate   timeStamp
1638    38      6016    57:07.3
1638    58      4512    57:07.3
3478    84      4512    57:07.3
1572    85      4512    57:07.3
1638    90      4512    57:07.3
1638    91      6016    57:07.3
1638    93      4512    57:07.3
3478    3376    4512    57:07.3
1572    3377    4512    57:07.3
1280    3378    15040   57:07.3
6168    3379    15040   57:07.3
6167    3380    15040   57:07.3
1572    3840    4512    57:07.3
3478    3841    4512    57:07.3
3478    3854    6016    57:07.3

CODE

grouped = ecmbw.groupby(['CAID','PID'])
nrows = int(math.ceil(len(grouped)/2.))

fig, axs = plt.subplots(nrows,2)

for ax in axs.flatten():
    for i, j in grouped:
        j.plot(x='timeStamp',y='BitRate',ax=ax)
     ax = axs.next()

RESULT
Image

0 个答案:

没有答案