作者:
cosmoSJ (cosmoSJ)
2016-02-12 14:18:37大家好,新年恭喜
有個問題困擾我很久想請教一下大家
目前在做投資績效回測的時候,因為要將結果輸出成圖比較容易確認
結果發現如果圖用show的方法,可以正確顯示坐標軸
但是如果savefig後,他的座標軸就會不見
範例如下
正常的
http://imgur.com/CSkxdA3
如果用saveig,會變成這個
http://imgur.com/yQEHyw2
附上原始碼如下
fig = plt.figure(facecolor='#07000d')
ax1 = plt.subplot2grid((3,2), (1,0), rowspan=4, colspan=4,
axisbg='#07000d')
candlestick_ohlc(ax1,newAr[:],width=.6,colorup='#ff1717',colordown='#53c156')
par1 = ax1.twinx()
par1.plot(datenumArr[:],AcctAmtArr[:],color = "red",linewidth=1)
ax1.grid(True, color='w')
ax1.xaxis.set_major_locator(mticker.MaxNLocator(10))
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
plt.gca().yaxis.set_major_locator(mticker.MaxNLocator(prune='upper'))
ax1.tick_params(axis='x', colors='w')
plt.ylabel('Stock price and Volume')
plt.sca(par1)
fig.savefig(u"test.png", format="png")
一直都試不出來問題在哪,只能請大家幫忙看看
感謝各位前輩