I want to plot several subplots. Depending on the data it might by a N x M array of plots, but also only a single plot or a 1 x M or N x 1 array.
The code I’m using is as follows which works for M x N arrays. However if M or N or both are 1 I get the Error:
matplotlib IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
Sure I could do a switch case for the 4 different possibilities but there must be a better way?
fig, axs = plt.subplots(max_N, max_N)
for N in range(max_N):
for M in range(max_N):
axs[N, M].plot(...)