輸入需要對比的兩列矩陣及標(biāo)題名稱的字符串湃密,調(diào)用函數(shù)出散點評估圖
function plot_scatter(x,y,ch_title)
? ? % 調(diào)用方式 e.g. plot_scatter(no2_obs,no2_model,'NO_2')
? ? % 剔除兩組數(shù)據(jù)的缺測值及極端異常值
? ? x(x>1000)=nan;y(y>1000)=nan;
? ? max_o3 = max([max(x) max(y)]);
? ? iok = find(isnan(x)==0 & isnan(y)==0 & y~=0);
? ? x=x(iok);y=y(iok);
? ? % 計算觀測與臺站相關(guān)性妻顶,并輸出相關(guān)系數(shù)及顯著性
? ? [r_m p_m]=corrcoef(x,y);
? ? r=r_m(1,2);p=p_m(1,2);
? ? k=polyfit(x,y,1);y_line=polyval(k,x); %線性擬合佃却,并輸出系數(shù)
? ? a=k(1);b=k(2);
? ? % 畫散點圖及一次擬合值線
? ? fontsize = 18;
? ? scatter(x,y,'filled');hold on;
? ? h1=plot(x,y_line,'LineWidth',2,'Color',[0.8 0.4 0.4]);hold on;
? ? plot([0 max_o3],[0 max_o3],'k-','linewidth',1);
? ? axis([0 max_o3 0 max_o3])
? ? xlabel('Observation');ylabel('MAX-DOAS');title(ch_title)
? ? set(gca,'FontSize',fontsize,'FontName','Times New Roman','FontWeight','bold')
? ? % 添加擬合方程
? ? haxes1 = get(h1, 'Parent'); %獲取屬性
? ? xlim = get(haxes1, 'XLim'); ylim = get(haxes1, 'YLim');
? ? dx=(xlim(2)-xlim(1))/10;dy=(ylim(2)-ylim(1))/15; %根據(jù)需求選擇間隔
? ? if b>0
? ? ? ? text(xlim(1)+dx,ylim(2)-dy,strcat('y = ',32,num2str(round(a,2)),'x +',32,num2str(round(b,2))),'FontSize',fontsize,'FontName','Times New Roman','FontWeight','bold');
? ? else
? ? ? ? text(xlim(1)+dx,ylim(2)-dy,strcat('y = ',32,num2str(round(a,2)),'x -',32,num2str(abs(round(b,2)))),'FontSize',fontsize,'FontName','Times New Roman','FontWeight','bold');
? ? end? ? ?
? ? ? ? if p<0.05
? ? ? ? text(xlim(1)+dx,ylim(2)-2*dy,strcat('r = ',32,num2str(round(r,2)),', p < 0.05'),'FontSize',fontsize,'FontName','Times New Roman','FontWeight','bold');
? ? else
? ? ? ? text(xlim(1)+dx,ylim(2)-2*dy,strcat('r = ',32,num2str(round(r,2))),'FontSize',fontsize,'FontName','Times New Roman','FontWeight','bold');
? ? end?
? ? set(gca,'XLim',xlim,'YLim',ylim);
end