Yes, there is, but let's clean up that code while we're at it:
f, axs = plt.subplots(2, 3)
for i in range(5): #are you sure you don't mean 2x3=6?
axs.flat[i].plot(x, u)
axs.flat[i].set_xlim(xmin, xmax)
axs.flat[i].set_ylim(ymin, ymax)
Using axs.flat
transforms your axs
(2,3) array of Axes into a flat iterable of Axes of length 6. Much easier to use than plt.gcf().get_axes()
.
If you only are using the range
statement to iterate over the axes and never use the index i
, just iterate over axs
.
f, axs = plt.subplots(2, 3)
for ax in axs.flat: #this will iterate over all 6 axes
ax.plot(x, u)
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)