【发布时间】:2018-04-26 20:30:45
【问题描述】:
我有一个关于在 matplotlib 的循环中使用 fig、axes 函数的问题。 我正在尝试在一个循环中创建一些带有多个子图的图(子图的数量不固定),如下所示:
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)
有没有办法让这项工作无需在函数中返回轴并传递它?如果我使用 plt.figure 而不是 fix,axes,那么我可以简单地使用 plt.figure(fig_no) 更新任何图形。
【问题讨论】:
标签: python matplotlib plot