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脚本中执行它。一旦执行,我想要一个窗口弹出以查看与该代码相关的图形,但它失败了。我怎么能修改这段代码才能起作用?
答案 0 :(得分:1)
使用iplot()
代替最后一行中的py_offline.plot()
,应该在浏览器窗口中打开绘图。
py_offline.plot(data, filename='simple_candlestick')
或
py_offline.plot(data)