我刚用过pandas dataframe& matplotlib绘制盘中ohlc +交易量。 但是ax1和ax2中的x-ticks似乎并不相互匹配。
这是不共享轴的图: http://imgur.com/a/cTHC2
如果我使用sharex = ax1,图表将变为: http://imgur.com/a/siPor
编码是
column_names = ['stockName','contract','unixStamp', 'dateStamp', 'excPrice', 'excVolume']
df = pd.read_csv(file,header=None, names = column_names)
df['Time']=pd.to_datetime(df.dateStamp)
df.set_index('Time',inplace = True)
df_ohlc = df['excPrice'].resample('1T').ohlc()
df_vol = df['excVolume'].resample('1T').sum()
df_full = pd.concat([df_ohlc, df_vol], axis=1)
#df_ohlc.insert(0, 'time' , df_ohlc.index)
print(df_full.head())
fig = plt.figure()
ax1 = plt.subplot2grid((5,4),(0,0),rowspan=4, colspan=4)
##ax1.axes.set_xticks(df_ohlc['time'])
candlestick2_ohlc(ax1, df_ohlc['open'], df_ohlc['high'],df_ohlc['low'],df_ohlc['close'],width=1, colorup='r', colordown='g')
ax2 = plt.subplot2grid((5,4),(4,0), sharex= ax1, rowspan=1, colspan=4)
ax2.plot(df_full.index, df_full['excVolume'] , '#00ffe8')
plt.legend()
plt.show()
如何修复图表以协调x轴? 谢谢!