下午好,
我想看看你们中谁能在几分钟内帮我做个蜡烛图。我已经设法在几天内绘制出它们的图形,但是我不知道如何在几分钟内完成它们。
附加代码。
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一天中的分钟数即可。完整的代码,供您在下面复制和粘贴,但我所做的只是更改width = 0.5为width = 0.5/(24*60)。
width
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()