簡體   English   中英

Jupyter Notebookly 沒有顯示圖表..(只是圖表)

[英]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包版本;

  • 蟒蛇 3.7.4
  • 情節 4.5.2
  • 麻木 1.16.6
  • 海生 0.9.0
  • 熊貓 0.25.3

請參閱 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM