(Adjusted to suggestions) I already have a function that performs some plot:
def plot_i(Y, ax = None): if ax == None: ax = plt.gca() fig = plt.figure() ax.plot(Y) plt.close(fig) return fig And I wish to use this to plot in a grid for n arrays. Let's assume the grid is (n // 2, 2) for simplicity and that n is even. At the moment, I came up with this:
def multi_plot(Y_arr, function): n = len(Y_arr) fig, ax = plt.subplots(n // 2, 2) for i in range(n): # assign to one axis a call of the function = plot_i that draws a plot plt.close(fig) return fig Unfortunately, what I get if I do something like:
# inside the loop plot_i(Y[:, i], ax = ax[k,j]) Is correct but I need to close figures each time at the end, otherwise I keep on adding figures to plt. Is there any way I can avoid calling each time plt.close(fig)?
Nsubplots in ann x mgrid.plot_ianaxparameter and switch to the object-oriented interface within it.