2015-05-05 21 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