2012-07-21 24 views
0

我有一批需要使用標準模板創建的圖表。問題在於Y軸中的數字數量因設置而異;這是導致一個問題,因爲我似乎無法得到佈局,以適應ylabel +數字沒有剪輯。matplotlib圖表的批量調整

有沒有關於如何選擇正確的值subplot_adjust或使tight_layout記住suptitle的建議?

代碼目前看起來大約是這樣的:

rc('text',usetex=True) 
rc('font',family='serif') 
mpl.rcParams.update({'font.size': 22}) 
fig = plt.figure(1,dpi=300,figsize=(4,4)) 
fig.suptitle(b.replace("_","-")) 
ax = fig.add_subplot(1,1,1) 
lx = 0 
for i in instances: 
    lx = max([lx,len(X[i])]) 
    plt.plot(X[i],Y[i]) 
plt.xlabel("X Label") 
plt.ylabel("Y Label") 
fig.subplots_adjust(bottom=0.1, top=0.9) # Works for some charts, not others! 
plt.savefig(b+".pdf",format="pdf") 
+0

全部在同一範圍內的數據的?如果是這樣,你可以嘗試修復所有圖上相同的y限制,以使得蜱(和數字的位數)相同。 – tacaswell 2012-07-22 20:55:12

+0

@tcaswell:甚至沒有;不過,我想我可以強制數字。我還計劃最終對這些圖進行網格化,所以我也將嘗試直接在matplotlib中創建一個子圖網格。我們將看到什麼效果最好。 – 2012-07-23 15:19:23

+0

你有沒有把這個整理出來? – tacaswell 2013-06-01 03:47:43

回答

0
majorFormattor = matplotlib.ticker.FormatStrFormatter('%0.1f') 
ax.yaxis.set_major_formatter(majorFormattor) 

Docs