0

我正在尝试使用 matplotlib 创建一个基本的烛台图,但在显示实际图形时遇到问题。我很确定问题是我没有正确配置 x 和 y 轴,过去几天我一直在尝试但迷路了。

以下是图表当前的样子:

当前图表

数据都在 6:30 - 1:00(太平洋时间)之间,我试图让图表格式化,以便它只显示该范围。

我目前有一个包含 390 个元组的数组,每个元组保存市场每分钟开放的信息。

前 20 个元组:

(735788.2708333334, 100.42199999999998, 100.37066666666666, 100.49666666666667, 100.30999999999999)
(735788.2715277778, 100.40166666666667, 99.80386666666668, 100.50318, 99.61001333333334)
(735788.2722222222, 99.82835999999999, 99.71597333333334, 100.01999333333333, 99.43113333333332)
(735788.2729166667, 99.73700000000002, 99.75814666666669, 100.08185333333331, 99.42368000000002)
(735788.2736111111, 99.79395999999998, 99.73145333333332, 100.03351333333333, 99.44720000000001)
(735788.2743055555, 99.70568666666667, 99.77659333333332, 99.89994000000002, 99.52147333333333)
(735788.275, 99.74577333333336, 99.63916, 99.90475333333332, 99.50369333333335)
(735788.2756944444, 99.63131333333332, 99.79678, 99.93578666666666, 99.51455333333334)
(735788.276388889, 99.79278666666667, 99.82032666666667, 100.00658666666668, 99.60532666666667)
(735788.2770833333, 99.78903333333334, 99.55625333333334, 99.8616, 99.39334666666666)
(735788.2777777778, 99.54983333333334, 99.6574, 99.78999999999999, 99.38213999999999)
(735788.2784722223, 99.65650666666667, 99.72088666666669, 99.88065333333333, 99.52334666666664)
(735788.2791666667, 99.71439333333333, 99.73757333333334, 99.87037333333335, 99.53099999999999)
(735788.2798611111, 99.75731999999999, 99.71152000000001, 99.87126666666664, 99.55641333333334)
(735788.2805555556, 99.72598666666667, 99.69014666666668, 99.86319333333333, 99.49409333333331)
(735788.28125, 99.69524, 99.62354000000002, 99.87518, 99.41418666666667)
(735788.2819444444, 99.59366000000001, 99.57455333333334, 99.74746, 99.42263333333335)
(735788.2826388889, 99.56687333333335, 99.64080000000003, 99.77255333333333, 99.43100000000001)
(735788.2833333333, 99.62504666666668, 99.72166666666664, 99.81258666666668, 99.51756666666667)
(735788.2840277777, 99.70745333333333, 99.76073333333332, 99.91593999999999, 99.59593333333332)

元组格式为:(时间、开盘、收盘、高、低)

时间是 date2num

代码:

fig = plt.figure(figsize(10,5))
ax = fig.add_axes([0.1, 0.2, 0.85, 0.7])
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.tick_params(axis='both', direction='out', width=2, length=8, labelsize=12, pad=8)
ax.spines['left'].set_linewidth(2)
ax.spines['bottom'].set_linewidth(2)
ax.set_xticklabels(timeAvg, rotation=45, horizontalalignment='right')
ax.set_ylabel('$', size='20')
ax.set_ylim([75,105])

candlestick(ax, listoftuples, width=0.5, colorup='g', colordown='r')
plt.show()
4

0 回答 0