【发布时间】:2015-07-10 15:12:46
【问题描述】:
我有一个这样的数据框:
value identifier
2007-01-01 0.781611 55
2007-01-01 0.766152 56
2007-01-01 0.766152 57
2007-02-01 0.705615 55
2007-02-01 0.032134 56
2007-02-01 0.032134 57
2008-01-01 0.026512 55
2008-01-01 0.993124 56
2008-01-01 0.993124 57
2008-02-01 0.226420 55
2008-02-01 0.033860 56
2008-02-01 0.033860 57
所以我对每个标识符进行分组:
df.groupby('identifier')
现在我想在网格中生成子图,每组一个图。我都试过了
df.groupby('identifier').plot(subplots=True)
或
df.groupby('identifier').plot(subplots=False)
和
plt.subplots(3,3)
df.groupby('identifier').plot(subplots=True)
无济于事。如何创建图表?
【问题讨论】:
-
查看
seaborn,它做得非常好。 -
谢谢,但我试图避免使用 seaborn 并仅使用 matplotlib。依赖和Windows环境等。
-
旧评论,但
seaborn是matplotlib的API。 Seaborn 将其减少到 1 行,无需任何数据帧转换:sns.relplot(kind='line', data=df.reset_index(), row='identifier', x='index', y='value')。
标签: python pandas plot group-by subplot