您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Matplotlib烛台在几分钟内

Matplotlib烛台在几分钟内

如此接近,但只有反复试验才能使您更进一步。糟糕的文档不是很好吗?

只需除以width一天中的分钟数即可。完整的代码,供您在下面复制和粘贴,但我所做的只是更改width = 0.5width = 0.5/(24*60)

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import dates, ticker
import matplotlib as mpl
from mpl_finance import candlestick_ohlc

mpl.style.use('default')

data = [('2017-01-02 02:00:00', '1.05155', '1.05197', '1.05155', '1.0519'),
    ('2017-01-02 02:01:00', '1.05209', '1.05209', '1.05177', '1.05179'),
    ('2017-01-02 02:02:00', '1.05177', '1.05198', '1.05177', '1.05178'),
    ('2017-01-02 02:03:00', '1.05188', '1.052', '1.05188', '1.052'),
    ('2017-01-02 02:04:00', '1.05196', '1.05204', '1.05196', '1.05203'),
    ('2017-01-02 02:06:00', '1.05196', '1.05204', '1.05196', '1.05204'),
    ('2017-01-02 02:07:00', '1.05205', '1.0521', '1.05205', '1.05209'),
    ('2017-01-02 02:08:00', '1.0521', '1.0521', '1.05209', '1.05209'),
    ('2017-01-02 02:09:00', '1.05208', '1.05209', '1.05208', '1.05209'),
    ('2017-01-02 02:10:00', '1.05208', '1.05211', '1.05207', '1.05209')]

ohlc_data = []

for line in data:
    ohlc_data.append((dates.datestr2num(line[0]), np.float64(line[1]), np.float64(line[2]), np.float64(line[3]), np.float64(line[4])))

fig, ax1 = plt.subplots()
candlestick_ohlc(ax1, ohlc_data, width = 0.5/(24*60), colorup = 'g', colordown = 'r', alpha = 0.8)

ax1.xaxis.set_major_formatter(dates.DateFormatter('%d/%m/%Y %H:%M'))
ax1.xaxis.set_major_locator(ticker.MaxNLocator(10))

plt.xticks(rotation = 30)
plt.grid()
plt.xlabel('Date')
plt.ylabel('Price')
plt.title('Historical Data EURUSD')
plt.tight_layout()
plt.show()
其他 2022/1/1 18:29:28 有485人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶