Question Details

No question body available.

Tags

python matplotlib

Answers (2)

May 12, 2026 Score: 1 Rep: 181,351 Quality: Low Completeness: 30%

Please make a minimal reproducible example explaining the result and what you want instead. We should be able to hit the Copy button and run the example with no modifications.

May 12, 2026 Score: 0 Rep: 7,509 Quality: Low Completeness: 50%

If you want to at least get rid of one of the loops, you can flatten the array containing the axes and iterate directly over them, e.g.,

items = [expcat, inccat, expmonth, incmonth]
fig, axes = plt.subplots(2, 2)

for n, ax in enumerate(axes.flat): ax.plot(items[n].cumsum(), color="red", linestyle="dashed", label=n)

or you could zip the flattened axes and items together, e.g.,

items = [expcat, inccat, expmonth, incmonth]
fig, axes = plt.subplots(2, 2)

for item, ax in zip(items, axes.flat): ax.plot(item.cumsum(), color="red", linestyle="dashed")