gpt4 book ai didi

python - 几分钟内的 Matplotlib 烛台

转载 作者:行者123 更新时间:2023-11-28 21:38:34 25 4
gpt4 key购买 nike

下午好

我想看看你们中是否有人可以帮助我在几分钟内制作出蜡烛图。我设法在几天内将它们绘制成图表,但我不知道如何在几分钟内完成。

附加代码。

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, 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()

最佳答案

如此接近,但只有反复试验才能使您走得更远。蹩脚的文档不是很棒吗?

简单地将宽度除以一天的分钟数。完整代码供您在下面复制和粘贴,但我所做的只是将 width = 0.5 更改为 width = 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()

关于python - 几分钟内的 Matplotlib 烛台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48081854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com