2016-02-26 106 views
3

我想將我的fill_between添加到圖例中,但它不起作用? 爲什麼它與其他地塊不同?下面是圖我現在有:添加fill_between到python中的圖例

enter image description here

plt.scatter(stageheight,discharge,color='b',label='measured data') 
plt.plot(stageheight_hecras,discharge_hecras,'y^',label='modeled with HEC-RAS') 
plt.plot(stageheight_masked,discharge_predicted,'r-',label='regression line measured data') 
plt.plot(stageheight_hecras,discharge_predicted_hecras,'g-',label='regression line HEC-RAS') 
plt.plot(stageheight_masked,upper,'r--',label='15% error measured data') 
plt.plot(stageheight_masked,lower,'r--') 
plt.plot(stageheight_hecras,upper_hecras,'g--',label='30% error HEC-RAS') 
plt.plot(stageheight_hecras,lower_hecras,'g--') 
plt.fill_between(stageheight_masked,upper,lower,facecolor='red',edgecolor='red',alpha=0.5,label='test') 
plt.fill_between(stageheight_hecras,upper_hecras,lower_hecras,facecolor='green',alpha=0.5) 
plt.axhline(y=0.6,xmin=0,xmax=1,color='black',linewidth = 4.0,label='measuring range') 
plt.text(0.02,0.7,'measured rating curve $Q = 1.37H^2 + 0.34H - 0.007$\nmodeled ratign curve $Q = 1.14H^2 - 0.51H + 0.07$',bbox=dict(facecolor='none',edgecolor='black',boxstyle='square')) 
plt.title('Rating curve Catsop') 
plt.ylabel('discharge$[m^3/s]$') 
plt.ylim(0,2.5) 
plt.xlim(0,1.2) 
plt.xlabel('stageheight$[m]$') 
plt.legend(loc='upper left', title='Legend') 
plt.grid(True) 
plt.show() 

回答

2

您使用的是什麼版本的matplotlib

這應該工作,如果你升級到v1.5.0或更高版本。請參閱此處瞭解更多詳情:https://github.com/matplotlib/matplotlib/pull/3303#event-182205203

+0

我在哪裏可以查看我使用的版本? –

+0

'import matplotlib; matplotlib .__ version__':''1.5.1'' – tom

+0

我有版本1.3.1,我怎樣才能下載1.5.1 –