[英]Importing and displaying a plotly graph saved as an html file into Jupyter Notebook
[英]Jupyter notebook plotly not showing graph.. (just graph)
在 jupyter notebook 中,我的代码确实运行了……只是没有显示图表。
我试过很多方法..
我的示例代码,图片。
我的代码和图片
import plotly.offline as pyo
import plotly.graph_objs as go
pyo.init_notebook_mode()
trace0 = go.Scatter(
x=[1, 2, 3, 4],
y=[5, 8, 2, 7]
)
trace1 = go.Scatter(
x=[1, 2, 3, 4],
y=[1, 5, 13, 2]
)
data = [trace0, trace1]
pyo.iplot(data, filename = 'ex')
而且,我点击了一个按钮; 下载图为png...
下载 newplot.svg; 打开一个文件...
探险家
捕获 newplot.svg
在新的水龙头资源管理器中,此图显示良好。
为什么在 jupyter notebook 中不显示图表?
以防万一版本。 添加我的python包版本;
请参阅 plotly 的入门文档...
要在经典的 Jupyter Notebook 中使用,请使用 pip 安装 notebook 和 ipywidgets 包...
$ pip install "notebook>=5.3" "ipywidgets>=7.2"
要在 JupyterLab 中使用,请使用 pip 安装 jupyterlab 和 ipywidgets 包...
$ pip install jupyterlab "ipywidgets>=7.5"
然后运行以下命令来安装所需的 JupyterLab 扩展(请注意,这将需要安装节点):
JupyterLab 渲染器支持
jupyter labextension install jupyterlab-plotly@4.13.0
可选:Jupyter 小部件扩展
jupyter labextension install @jupyter-widgets/jupyterlab-manager plotlywidget@4.13.0
我的方法是 Jupyter notebook 默认程序(Exploere -> Chrome)
# Import the necessaries libraries
import plotly.offline as pyo
import plotly.graph_objs as go
# Set notebook mode to work in offline
pyo.init_notebook_mode()
# Create traces
trace0 = go.Bar(
x=[1, 2, 3, 4],
y=[10, 15, 13, 17]
)
trace1 = go.Bar(
x=[1, 2, 3, 4],
y=[16, 5, 11, 9]
)
# Fill out data with our traces
data = [trace0, trace1]
# Plot it and save as basic-line.html
pyo.plot(data, filename = 'Test-bar.html', auto_open = False)
# Show HTML
from IPython.display import HTML
HTML(filename='Test-bar.html')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.