I have a question about using fig, axes function in a loop in matplotlib. I am trying to create a few plots with multiple subplots (the number of subplots isn not fixed) in a loop as follows:
def start_plot(self):
if self.running:
run_fig, run_ax = plt.subplots(*self.matrix)
if self.histogram:
hist_fig, hist_ax = plt.subplots(*self.matrix)
def create_signal_plots(self, iwindow, window_name):
if self.running:
run_ax[iwindow+1].plot(running_perf, label=window_name) # throws error run_ax not recognized
if self.histogram:
hist_ax[iwindow+1].hist(timeseries, label=window_name)
plot = plot_class(run =1, hist =1, matrix = get_matrix(*args)) # e.g. matrix = (3,2)
for istrat, strat in enumerate(strats):
plot.start_plot()
for iwindow, window in enumerate(windows):
plot.create_plots(iwindow, window)
Is there a way to make this work without having to return axes in function and pass it around? If I use plt.figure instead of fix,axes, then i can simply update any figure using plt.figure(fig_no).