2017-12-04 2 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) 

또는 두에서 실행해야하는 경우 다른 셀을 사용하려면 출력을 표시해야합니다.

세포 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)