本文介绍了此matplotlib.finance.candlestick2_ochl代码会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知道该错误.csv文件来自pd.datareader.但是我认为这与数据读取器无关.我使用的csv文件是在出口前完成的,它是完整的.我认为"candlestick2_ochl()"函数有问题

Have no idea about the error.The csv file is from pd.datareader. ButI think it's not about datareader. the csv file i used is exported mouths ago, and it's complete.I think it's something wrong with "candlestick2_ochl()" function

    import datetime as dt
    import matplotlib.pyplot as plt
    from matplotlib import style
    from matplotlib.finance import candlestick2_ochl
    import pandas as pd
    import pandas_datareader.data as web
    import matplotlib.dates as mdates
    style.use('ggplot')

    df = pd.read_csv('tsla.csv', parse_dates=True, index_col=0)
    df['100ma'] = df['Adj Close'].rolling(window=100, min_periods=0).mean()

    df = df.reset_index()
    df['Date'] = df['Date'].map(mdates.date2num)
    print(df.head())             

    ft = plt.figure()
    ax1 = plt.subplot2grid((6,1), (0,0), rowspan=5, colspan=1)
    ax1.xaxis_date()
    ax2 = plt.subplot2grid((6,1), (5,0), rowspan=1, colspan=1, sharex=ax1)


    candlestick2_ochl( ax1,df['Open'], df['Adj Close'], df['High'], df['Low'], width=.75, colorup='g', colordown='r', alpha=0.75)

    ax1.plot(df['Date'], df['100ma'])
    ax2.bar(df['Date'], df['Volume'])

    plt.show()

推荐答案

由于Yahoo更新了其API,因此它可能已损坏. pandas_datareader将不再起作用

It is probably broken since Yahoo has updated its API. pandas_datareader will not work any more

作为临时修复程序,您可以下载fix-yahoo-finance软件包以使其再次起作用.您应该可以通过pip安装此软件包,

As a temporary fix, you can download the fix-yahoo-finance package to get this to work again. You should be able to pip install this package,

pip install fix-yahoo-finance

然后只需导入fix-yahoo-finance并重新运行即可.

Then just import the fix-yahoo-finance and re-rerun.

这篇关于此matplotlib.finance.candlestick2_ochl代码会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 22:12