2017-08-28 68 views
0

我試圖嵌入由openMdao生成到Jupyter筆記本採用下面的代碼N2 digaram:如何嵌入Jupyter筆記本的OpenMDAO N2圖

from openmdao.api import Problem 

from openmdao.examples.beam_tutorial import BeamTutorial 
from openmdao.api import view_model 
from IPython.core.display import display, HTML 
top = Problem() 
top.root = BeamTutorial() 

top.setup(check=False) 
view_model(top, embed=True, show_browser=False, 
outfile='partition_tree_n2.html') 
display(HTML(filename='partition_tree_n2.html')) 

這正常,但顯示了圖的工具欄中沒有圖,也給出了錯誤:

Javascript error adding output! 
SyntaxError: Unexpected token > 
See your browser Javascript console for more details. 

的JavaScript控制檯上的錯誤是:

SyntaxError: Unexpected token > 
at eval (<anonymous>) 
at Function.globalEval (jquery.min.js:4) 
at init.domManip (jquery.min.js:5) 
at init.append (jquery.min.js:5) 
at OutputArea._safe_append (outputarea.js:440) 
at OutputArea.append_display_data (outputarea.js:638) 
at OutputArea.append_output (outputarea.js:330) 
at OutputArea.handle_output (outputarea.js:243) 
at output (codecell.js:365) 
at Kernel._handle_output_message (kernel.js:1196)) 

如何解決此問題或以其他方式嵌入Jupyter Notebook中的OpenMDAO N2圖表?

回答

0

更多的研究之後,我相信這是因爲HTML包括未在允許使用HTML JavaScript以及一個可能的解決方案是使用iframe如下面:

from openmdao.api import Problem 

from openmdao.examples.beam_tutorial import BeamTutorial 
from openmdao.api import view_model 
from IPython.core.display import display, HTML 
from IPython.display import IFrame 
top = Problem() 
top.root = BeamTutorial() 

top.setup(check=False) 
view_model(top, embed=True, show_browser=False, outfile='partition_tree_n2.html') 
display(IFrame(src='partition_tree_n2.html',width=1300,height=700)) 

它仍然會是不錯的設定寬度和高度,如果有人想提出更好的答案。