Matplotlib candlestick axis plotting

时间:2015-07-28 23:06:16

标签: python matplotlib candlestick-chart

I'm trying to create a basic candle stick graph using matplotlib, but am having problems displaying the actual graph. I'm pretty sure the problem is i'm not configuring the x & y axis correctly, I have been trying for the last couple days but am lost.

Here is what the graph looks like currently:

current graph

The data is all between 6:30 - 1:00 (pacific time), i'm trying to get the graph to format so that it only shows that range.

I currently have an array of 390 tuples, each tuple holding information for each minute the market is open.

first 20 tuples:

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

tuple format is: (time, open, close, high, low)

time is date2num

Code:

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

0 个答案:

没有答案
相关问题