![](/img/trans.png)
[英]Plotly output in Jupyter notebook to be saved when exported as HTML
[英]Importing and displaying a plotly graph saved as an html file into Jupyter Notebook
我是編程新手,所以如果這個問題看起來很簡單,請原諒。
我一直在使用 Python 及其庫來制作繪圖。 我正在嘗試導入我使用 plotly 圖形庫繪制的交互式圖形並將其顯示在 Jupyter 筆記本中。
圖形保存為 html 文件。 我需要圖形保留為 html 文件以保留圖形的功能和交互性(放大/縮小、更改比例、隱藏某些數據等)。
到目前為止,我已經寫出了這段代碼:
import plotly
import os
os.chdir(r'C:\Users\alsha\Documents\CE-CERT - SIGI\CMC Data')
from IPython.display import HTML
HTML(filename="./CopperMountainCollegeEntireInterval.html")
我不知道要編寫什么代碼來顯示實際圖形,如果得到任何幫助,我將不勝感激。
我可能遲到了一年,但最簡單的方法是從 IPython.display 導入 IFrame 並像這樣使用它
from IPython.display import IFrame
IFrame(src='path_to_html', width=500, height=500)
要完成 Luca R 答案(他的解決方案工作正常):不過,在我的情況下,我注意到要使用 IFrame,我需要將 html 文件放在與我的筆記本相同的目錄中(或在筆記本下的子目錄中),然后使用相對路徑。 這可能是由於常見的瀏覽器安全設置(更多信息來自https://community.plotly.com/t/displaying-html-file-generated-by-plotly-offline-in-a-jupyter-notebook/19586 )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.