【问题标题】:How do I generate a candlestick chart from Morningstar data using matplotlib and mpl_finance?如何使用 matplotlib 和 mpl_finance 从晨星数据生成烛台图?
【发布时间】:2018-06-14 23:53:59
【问题描述】:

我想从晨星导入数据并生成烛台图。

import numpy as np
import pandas as pd
import pandas_datareader.data as web
import mpl_finance as mpf
import matplotlib.pyplot as plt


AAPL = web.DataReader('AAPL', 'morningstar', start = '1/1/2000',end =  '5/29/2018')


fig, ax = plt.subplots(figsize = (8,5))
fig.subplots_adjust(bottom=0.2)
mpf.candlestick_ohlc(ax, AAPL, width = 0.6, colorup = 'b', colordown = 'r', alpha = 0.75)
ax.xaxis_date()
ax.autoscale_view()
ax.xaxis.grid(True, 'major')
ax.grid(True)

我收到一个错误:

TypeError: 不支持的操作数类型 -: 'str' 和 'str'

非常感谢任何帮助

【问题讨论】:

    标签: python matplotlib candlestick-chart


    【解决方案1】:

    您可以尝试将数据转换为浮点数:AAPL.astype(float),看起来那里可能是字符串而不是数字。

    另外我认为你必须使用带有mpl_finance candlestick_ohlc的序数日期:

        zip(mdates.date2num(AAPL.index.to_pydatetime()), AAPL['Open'], AAPL['High'], AAPL['Low'], AAPL['Close'], AAPL['Volume'])
    

    然后在你的candlestick_ohlc 中使用它而不是AAPL

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多