Plotly 简明教程
Plotly - Plotting Inline with Jupyter Notebook
在本章中,我们将学习如何在 Jupyter Notebook 中执行内嵌绘图。
为了在笔记本中显示绘图,你需要按照如下所示初始化 Plotly 的笔记本模式 -
from plotly.offline import init_notebook_mode
init_notebook_mode(connected = True)
将其余脚本保持原样,并按下 Shift+Enter 运行笔记本单元格。绘图将在笔记本内部脱机显示。
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 的输出如下所示 -
绘图输出显示 tool bar 中的 top right 。它包含用作 png, zoom in and out, box and lasso, select and hover. 下载的按钮