在线使用

import plotly 
plotly.tools.set_credentials_file(username='yourAccount', api_key='xxxxxx')

plotly.tools.set_config_file(world_readable=True,
                             sharing='public')

import plotly.plotly as py
import plotly.graph_objs as go

trace0 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[10, 15, 13, 17]
)
trace1 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[16, 5, 11, 9]
)
data = [trace0, trace1]

py.plot(data, filename = 'basic-line', auto_open=True)

离线使用

import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
plot([go.Scatter(x=[1, 2, 3], y=[3, 1, 6])])

图形会输出到本地html文件中

iplot([{"x": [1, 2, 3], "y": [3, 1, 6]}])

这样会直接输出结果