我正在尝试使用mpl_finance
,
我没有一个好的情节,而是一个看起来像这样的丑陋斑点:
这是我的代码:
import pandas
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter
from mpl_finance import candlestick_ohlc
# candles looks like this:
# [DatetimeIndex(['2018-11-05 11:00:00', '2018-11-05 12:00:00',
# '2018-11-05 13:00:00', '2018-11-05 14:00:00',
# '2018-11-05 15:00:00', '2018-11-05 16:00:00',
# '2018-11-05 17:00:00', '2018-11-05 18:00:00',
# '2018-11-05 19:00:00', '2018-11-05 20:00:00'],
# dtype='datetime64[ns]', name='date', freq=None), array([0.9432 , 0.94233, 0.94175, 0.94218, 0.94278, 0.94331, 0.94289,
# 0.94447, 0.94523, 0.94599]), array([0.94328, 0.94245, 0.94268, 0.9428 , 0.94404, 0.94352, 0.94458,
# 0.94534, 0.94608, 0.94619]), array([0.9423 , 0.94169, 0.94173, 0.9417 , 0.94213, 0.94288, 0.94283,
# 0.94387, 0.94515, 0.94504]), array([0.94234, 0.94174, 0.94218, 0.94278, 0.94331, 0.94289, 0.94447,
# 0.94523, 0.94599, 0.94515])]
fig, ax = plt.subplots()
dates = mdates.date2num(candles[0].to_pydatetime())
quotes = [tuple([dates[i],
candles[1][i],
candles[2][i],
candles[3][i],
candles[4][i]]) for i in range(len(dates))] #_1
candlestick_ohlc(ax, quotes, width=0.6)
fig.autofmt_xdate()
fig.tight_layout()
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
ax.grid(True)
plt.show()
我已经尝试了很多事情,但是不知道这里出了什么问题,有什么线索吗?
先谢谢。