用Python绘制蜡烛棒

用Python绘制蜡烛棒,python,pandas,plotly,candlestick-chart,Python,Pandas,Plotly,Candlestick Chart,我正在尝试用python绘制蜡烛棒图。这是我的密码 from pandas_datareader import data as pdr import plotly.plotly as py import plotly.graph_objs as go import fix_yahoo_finance as yf yf.pdr_override() mcd = pdr.get_data_yahoo("MCD", start="2004-01-01", end="2005-07-31") mcd_

我正在尝试用python绘制蜡烛棒图。这是我的密码

from pandas_datareader import data as pdr
import plotly.plotly as py
import plotly.graph_objs as go
import fix_yahoo_finance as yf

yf.pdr_override()
mcd = pdr.get_data_yahoo("MCD", start="2004-01-01", end="2005-07-31")
mcd_candle = go.Candlestick(x=mcd.index,open=mcd.Open,high=mcd.High,low=mcd.Low,close=mcd.Close)
data = [mcd_candle]
py.iplot(data, filename='Candle Stick')
这就是我得到的错误

PlotlyError: Because you didn't supply a 'file_id' in the call, we're assuming you're trying to snag a figure from a url. You supplied the url, '', we expected it to start with 'https://plot.ly'.

你知道我怎么画蜡烛棒形图吗?

问题一定是因为你没有提供
用户名和
api密钥,你将从
https://plot.ly/settings/api
链接。如果要使用
plotly online
创建此图形。首先创建一个帐户,然后获取
用户名
api密钥
,并将其插入下面的代码中

from pandas_datareader import data as pdr
import plotly.plotly as py
import plotly.graph_objs as go
import fix_yahoo_finance as yf
py.sign_in('<<username here>>', '<<api key here>>')
yf.pdr_override()
mcd = pdr.get_data_yahoo("MCD", start="2004-01-01", end="2005-07-31")
mcd_candle = go.Candlestick(x=mcd.index,open=mcd.Open,high=mcd.High,low=mcd.Low,close=mcd.Close)
data = [mcd_candle]
py.iplot(data, filename='Candle Stick')

如果这些库尚未存在,请确保使用
pip
安装库
pandas\u datareader
fix\u yahoo\u finance

通过实现脱机方法,我的代码正在运行,但看不到图形输出。代码运行时没有任何错误。我用的是水蟒斯派德。Python 3。x@DebdiptaMajumdar很抱歉,您需要使用
py_offline.plot
而不是
py_offline.iplot
使用spyder时,请参阅
from pandas_datareader import data as pdr
import plotly.offline as py_offline
import plotly.graph_objs as go
import fix_yahoo_finance as yf
py_offline.init_notebook_mode()

yf.pdr_override()
mcd = pdr.get_data_yahoo("MCD", start="2004-01-01", end="2005-07-31")
mcd_candle = go.Candlestick(x=mcd.index,open=mcd.Open,high=mcd.High,low=mcd.Low,close=mcd.Close)
data = [mcd_candle]
py_offline.iplot(data, filename='Candle Stick')
#for Spyder plotting use the below line instead
#py_offline.plot(data, filename='Candle Stick')