带有标准python脚本的弹出图表

时间:2018-04-16 21:30:56

标签: python plotly

import plotly.plotly as py
import plotly.graph_objs as go
from plotly.offline import iplot
import plotly.offline as py_offline

import pandas_datareader as web
from datetime import datetime

py_offline.init_notebook_mode()

df = web.DataReader("aapl", 'morningstar').reset_index()

trace = go.Candlestick(x=df.Date,
                       open=df.Open,
                       high=df.High,
                       low=df.Low,
                       close=df.Close)
data = [trace]
iplot(data, filename='simple_candlestick')

该代码在jupyter笔记本中运行良好。现在,我想在标准的python脚本中执行它。一旦执行,我想要一个窗口弹出以查看与该代码相关的图形,但它失败了。我怎么能修改这段代码才能起作用?

1 个答案:

答案 0 :(得分:1)

使用iplot()代替最后一行中的py_offline.plot(),应该在浏览器窗口中打开绘图。

py_offline.plot(data, filename='simple_candlestick')

py_offline.plot(data)