簡體   English   中英

如何使用matplotlib和mpl_finance從Morningstar數據生成燭台圖?

[英]How do I generate a candlestick chart from Morningstar data using matplotlib and mpl_finance?

我不想從Morningstar導入數據並生成燭台圖。

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'不支持的操作數類型

任何幫助,不勝感激

您可以嘗試將數據轉換為浮點數: 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使用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM