2017-11-14 14 views
0

fig、axes functionsをmatplotlibのループ内で使用することに関する質問があります。 私は次のようにループ内に複数のサブプロット(サブプロットの数が固定されていないISN)といくつかのプロットを作成しようとしています:ループmatplotlibの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) 

機能に軸を返すことなく、この作品を作るための方法がありますし、それを回す? fix、axesの代わりにplt.figureを使用すると、plt.figure(fig_no)を使用して任意のFigureを単純に更新できます。

答えて

0

run_figrun_axをインスタンス属性としてオブジェクトに格納し、そのオブジェクトの他のメソッドからアクセスできます。これはselfを使用して行われます。 start_plot中など

使用self.run_fig、およびcreate_signal_plotsのように:

def start_plot(self): 
    if self.running: 
     self.run_fig, self.run_ax = plt.subplots(*self.matrix) 
    if self.histogram: 
     self.hist_fig, self.hist_ax = plt.subplots(*self.matrix) 

def create_signal_plots(self, iwindow, window_name): 
    if self.running: 
     self.run_ax[iwindow+1].plot(running_perf, label=window_name) # throws error run_ax not recognized 
    if self.histogram: 
     self.hist_ax[iwindow+1].hist(timeseries, label=window_name) 
関連する問題