If you want to use nan
as the workaround, you can try this:
def fire_m(x, y, i, j=np.nan):
if j == np.nan:
ax[i].plot(x, y)
else:
ax[i,j].plot(x, y)
Another option is to use numpy.ravel_multi_index
. This will convert the i, j
-coordinate to a single index in a flattened version of the array.
def fire_m(x, y, i, j):
n = np.ravel_multi_index([i, j], ax.shape)
ax.flatten()[n].plot(x, y)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…