我有一个包含许多具有相同结构的聚合数据框的列表。
我想在同一个图形上绘制每个数据框中的两列。
我使用了这个代码片段,但它为每个数据框提供了一个单独的图:
# iterate through a list
for df in frames:
df.plot(x='Time', y='G1', figsize=(16, 10))
plt.hold(True)
plt.show()
如果您对每个集合都进行了索引,则可以将所有集合连接起来并立即绘制它们,而无需进行迭代。
# If not indexed:
# frames = [df.assign(sample=i) for i, df in enumerate(frames)]
df = pd.concat(frames).pivot(index='Time', columns='sample', values='G1')
df.plot(figsize=(16, 10));
这有助于确保您的数据对齐并且plt.hold
在 matplotlib 2.0 中被弃用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句