输入需要对比的两列矩阵及标题名称的字符串,调用函数出散点评估图
function plot_scatter(x,y,ch_title)
% 调用方式 e.g. plot_scatter(no2_obs,no2_model,'NO_2')
% 剔除两组数据的缺测值及极端异常值
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);
% 计算观测与台站相关性,并输出相关系数及显著性
[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); %线性拟合,并输出系数
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; %根据需求选择间隔
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