2015-05-05 147 views
1

我試圖減小我的數字與標題和圖例附加的大小。雖然實際數字取決於我的喜好,但圖例仍然很大,標題從圖像中消失。包含在我的一個地塊的示例中。Matplotlib子圖圖尺寸

enter image description here

下面是我的代碼,繪製該數據。有沒有人有建議讓這看起來更清潔?謝謝!

fig, ax = plt.subplots(figsize=(3,2.25)) 
ax.plot(df3['difference'],'r-',label="Observations") 
ax.plot(df4['difference'],'b-',label='MERRA') 
ax.set_xlim(0,205) 
ax.set_ylim(-60,60) 
plt.xlabel('Year') 
plt.ylabel('Snow Depth Departures(cm)') 
plt.title('Station '+str(stations[c])+' Snow Depth Correlations R='+str("%0.2f"%corr[0])+'') 
ax.autoscale(False) 
ax.set_xticks(np.arange(0,193,48)) 
ax.set_xticklabels(['1979','1983','1987','1991','1995']) 
plt.legend(loc='best') 

#plt.show() 
plt.savefig('Z:/Dan/'+str(stations[c])+'CorrPlot.png') 

回答

1

我想你差不多已經有了。嘗試在ax上設置xlabelylabel,titlelegend

fig, ax = plt.subplots(figsize=(3,2.25)) 
ax.plot(df3['difference'],'r-',label="Observations") 
ax.plot(df4['difference'],'b-',label='MERRA') 
ax.set_xlim(0,205) 
ax.set_ylim(-60,60) 
ax.set_xlabel('Year') 
ax.set_ylabel('Snow Depth Departures(cm)') 
ax.set_title('Station '+str(stations[c])+' Snow Depth Correlations R='+str("%0.2f"%corr[0])+'') 
ax.autoscale(False) 
ax.set_xticks(np.arange(0,193,48)) 
ax.set_xticklabels(['1979','1983','1987','1991','1995']) 
ax.legend(loc='best') 
+0

您還可以添加'字號='small''到'legend'電話。在製作小圖時很有用。 – cphlewis

+0

@cphlewis添加更改並編輯回覆帖子。仍然有點sc。。 – DJV

+0

沒關係,製作字體大小和指定的數字,一切都合適。謝謝! – DJV

1

這就是我想出了(用隨機數據):

import matplotlib.pyplot as plt 
import numpy as np 

diff1 = np.random.randint(-50, 40, 193) 
diff2 = np.random.randint(-55, 40, 193) 
corr = [0.5] 

fig, ax = plt.subplots(figsize=(3,2.25)) 
ax.plot(diff1,'r-',label="Observations") 
ax.plot(diff2,'b-',label='MERRA') 
ax.set_xlim(0,205) 
ax.set_ylim(-60,60) 
label = ax.set_xlabel('Year', fontsize=8) 
ax.xaxis.set_label_coords(1.06, 0) 
label = ax.set_ylabel('Snow Depth Departures(cm)', fontsize=8) 
ax.yaxis.set_label_coords(-0.087, 0.5) 
plt.title('Station 5555555 \nSnow Depth Correlations R='+str("%0.2f"%corr[0])+'', fontsize=10, y=0.875) 
ax.autoscale(False) 
ax.set_xticks(np.arange(0,193,48)) 
ax.set_xticklabels(['1979','1983','1987','1991','1995']) 
plt.tick_params(axis='both', which='major', labelsize=6) 
leg = plt.legend(loc=4, fontsize=8) 
leg.get_frame().set_alpha(0.85) 

plt.savefig('CorrPlot.png') 

enter image description here