[問題] matplotlib圖片存檔如何保留座標軸
大家好,新年恭喜
有個問題困擾我很久想請教一下大家
目前在做投資績效回測的時候,因為要將結果輸出成圖比較容易確認
結果發現如果圖用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")
一直都試不出來問題在哪,只能請大家幫忙看看
感謝各位前輩
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.228.46.8
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1455257919.A.C46.html
→
02/13 02:13, , 1F
02/13 02:13, 1F
→
02/13 11:21, , 2F
02/13 11:21, 2F
→
02/14 00:18, , 3F
02/14 00:18, 3F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章