Plotly - 使用 Jupyter Notebook 進行內聯繪圖



在本章中,我們將學習如何使用 Jupyter Notebook 進行內聯繪圖。

若要在 notebook 內顯示繪圖,你需要按照以下方法啟動 plotly 的 notebook 模式 −

from plotly.offline import init_notebook_mode
init_notebook_mode(connected = True)

保留其餘指令碼原樣,然後按 Shift+Enter 執行 notebook 單元格。圖形將離線顯示在 notebook 內部。

import plotly
plotly.tools.set_credentials_file(username = 'lathkar', api_key = '************')
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode(connected = True)

import plotly
import plotly.graph_objs as go
import numpy as np
import math #needed for definition of pi

xpoints = np.arange(0, math.pi*2, 0.05)
ypoints = np.sin(xpoints)
trace0 = go.Scatter(
   x = xpoints, y = ypoints
)
data = [trace0]
plotly.offline.iplot({ "data": data,"layout": go.Layout(title="Sine wave")})

Jupyter notebook 輸出將如下所示 −

Jupyter Notebook

繪圖輸出顯示 右上角工具欄。它包含用於以 png 下載放大和縮小框和套索選擇懸停 的按鈕。

Tool Bar
廣告
© . All rights reserved.