使用 Jupyter 注意book 内联绘图


在本章中,我们将学习如何使用 Jupyter 注意book 进行内联绘图。

为了在 notebook 中显示 plot,需要启动 plotly 的 notebook 模式,如下所示:

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 输出如下图所示:

Jupyter 注意book

绘图输出显示 tool bar at 右上 .它包含用于下载的按钮 png, 放大 和出,框和套索,选择和悬停。

Tool Bar