由于计算复杂性,我不得不使用整数索引在时间序列DataFrame上的.reset_index()之后的3个轴上绘制多个值:
plotSet = dataSet.reset_index(drop=True)
为了绘制烛台图,candlestick2_ohlc用于处理整数索引:
from mpl_finance import candlestick2_ohlc
candlestick2_ohlc(ax1, plotSet.open, plotSet.high, plotSet.low, plotSet.close, colorup='g', colordown='r')
尽管仅显示底部ax3,但所有3轴共享相同的x轴:
ax2 = fig.add_axes([0.0, 0.2, 1.0, 0.2], sharex=ax1)
ax3 = fig.add_axes([0.0, 0.0, 1.0, 0.2], sharex=ax1)
现在在共享的x轴上绘制了所有计算值(在整数索引上迭代),如何替换整数索引以显示日期索引,例如。在网格线[0,10,.. 60,70]上以%Y-%m-%d格式显示?
参考图集数据:
date close vwap vector
0 2019-07-31 229.619995 229.307489 0.454934
1 2019-08-01 228.899994 229.912447 0.441829
2 2019-08-02 232.029999 230.501370 0.374164
.. ... ... ... ...
75 2019-11-13 266.910004 268.070642 0.707007
76 2019-11-14 269.670013 268.694046 0.620086
77 2019-11-15 274.739990 270.131488 0.637069
我想分享如何用日期替换x轴索引。。>
# Initialise index list & date list
ix = []
id = []
# Assign index & dates in reverse order.. in steps of -5 for weekly periods
for i in range(len(plotSet.index)-1, 0, -5):
ix.append(i)
id.append(str(plotSet.date.iloc[i]).split()[0][2:])
# Set ticks to index & tick labels to date texts
ax1.set_xticks(ix)
ax1.set_xticklabels(id)