Plotting Pandas groupby groups using subplots and loop
Sounds like you want to iterate over the groups and the axes in parallel, so rather than having nested for
loops (which iterates over all groups for each axis), you want something like this:
for (name, df), ax in zip(grouped, axs.flat): df.plot(x='C1',y='C3', ax=ax)
You have the right idea in your second code snippet, but you're getting an error because axs
is an array of axes, but plot
expects just a single axis. So it should also work to replace next(axs)
in your example with ax = axs.next()
and change the argument of plot
to ax=ax
.