2017-12-04 13 views
0

は下記行われるように2つのセルを介して実行している場合、単一のセルを介して実行するとjupyterノートブックで動作しますが、失敗した次のスクリプトをしているIのステップノートブックの整理作業は?

セル1:

class Plotting(object): 

    def __init__(self, run, hist): 
     self.running = run 
     self.histogram = hist 

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

    def create_plots(self, iwindow, run_series, hist_series): 
     if self.running: 
      self.run_ax[iwindow].plot(run_series) 
     if self.histogram: 
      self.hist_ax[iwindow].hist(hist_series, histtype='step') 

plot = Plotting(run =1, hist =1) 
plot.start_plot() 

がセル2:

for iwindow in np.arange(2): 
    r = np.random.rand(20) 
    h = np.random.rand(50) 
    plot.create_plots(iwindow, r, h) 
+0

スクリプトとしてまたはJupyter内から実行するかどうかを任意の違いがあってはなりません。もちろん、この質問がすべての重要な詳細を隠しているので、わからないことがあります。 [mcve]を参照してください。 – ImportanceOfBeingErnest

+0

は今は大丈夫です。 – dayum

答えて

0

あなたは

%matplotlib inline 
import matplotlib.pyplot as plt 
import pandas as pd 
import numpy as np 

class Plotting(object): 

    def __init__(self, run, hist): 
     self.running = run 
     self.histogram = hist 

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

    def create_plots(self, iwindow, run_series, hist_series): 
     if self.running: 
      self.run_ax[iwindow].plot(run_series) 
     if self.histogram: 
      self.hist_ax[iwindow].hist(hist_series, histtype='step') 

plot = Plotting(run =1, hist =1) 
plot.start_plot() 

for iwindow in np.arange(2): 
    r = np.random.rand(20) 
    h = np.random.rand(50) 
    plot.create_plots(iwindow, r, h) 

それとも2でそれを実行する必要がある場合は、単一のセルでこれを実行しますどちらか別のセル、出力を表示する必要があります:

セル1

%%capture 
%matplotlib inline 
from IPython.display import display 
import matplotlib.pyplot as plt 
import pandas as pd 
import numpy as np 


class Plotting(object): 

    def __init__(self, run, hist): 
     self.running = run 
     self.histogram = hist 

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

    def create_plots(self, iwindow, run_series, hist_series): 
     if self.running: 
      self.run_ax[iwindow].plot(run_series) 
     if self.histogram: 
      self.hist_ax[iwindow].hist(hist_series, histtype='step') 

plot = Plotting(run =1, hist =1) 
plot.start_plot() 

セル2

for iwindow in np.arange(2): 
    r = np.random.rand(20) 
    h = np.random.rand(50) 
    plot.create_plots(iwindow, r, h) 
display(plot.run_fig) 
display(plot.hist_fig)