【发布时间】:2019-06-09 15:04:40
【问题描述】:
我有 200 种产品,我想绘制 time vs parameter 图表。我想出了一个代码,它可以为 20 种产品绘制图表并将它们显示在一个窗口中。
我想知道是否有办法在 10 个不同的窗口中绘制 200 个图作为子图,每个窗口包含 20 个图。
我的代码
grouped = dataset.groupby('product_number')
ncols = 4
nrows = int(np.ceil(grouped.ngroups/40))
fig, axes = plt.subplots(figsize=(12,4), nrows = nrows, ncols = ncols)
for (key, ax) in zip(grouped.groups.keys(), axes.flatten()):
grouped.get_group(key).plot(x='TimeElapsed', y='StepID', ax=ax, sharex = True, sharey = True)
ax.set_title('product_number=%d'%key)
ax.legend()
plt.show()
这段代码给了我一个包含 20 个子图的窗口,如下所示
【问题讨论】:
标签: python python-3.x pandas matplotlib pandas-groupby