Matlab-based density scatter plot drawing-from data analysis to complete plotting

created at 06-29-2021 views: 3

When calculating the correlation between two images at the pixel level, due to the high resolution of the image, it is impossible to draw a scatter plot directly to reflect the general trend, so it is necessary to use a density scatter plot to describe. The core of the scatter density map is to find the number of points in this range within the range of x and y, and the interval between x and y needs to be reasonably selected.

First of all, this article uses two ET data as an example, the resolution is 1000m, and the value range is 8 to 1100. The maximum difference between the two does not exceed 800. Choose 5 as the interval between the two images, and extract the following code

filemean='I:\蒸散发\各ET的均值和趋势\yr_SSEB_2003-2013年ET的均值.tif';
sseb=importdata(filemean);
filemean='I:\蒸散发\各ET的均值和趋势\yr_SSEBopYRB_2003-2013年ET的均值.tif';
ssebop=importdata(filemean);
sy1=find(sseb>0 & ssebop>0); % Find the valid value of both
sseb_1=double(sseb(sy1));
ssebop_1=double(ssebop(sy1));
valuesum=zeros(47961,3); % Is 47961 because the length of 8:5:1100 is 219, and the square of 219 is 47961
k=1;
for i=8:5:1100 %sseb
    sy=find(sseb_1>=i & sseb_1<i+5);
    j1=i+800;
    j2=i-800;
    if j1>1100
        j1=1100;
    end
    if j2<8
        j2=8;
    end
    for j=j2:5:j1 %ssebop
       sy2= find(ssebop_1>=j & ssebop_1<j+5);
       sy3=intersect(sy,sy2);
       cd=length(sy3);
       if length(cd)>0
           value=[i,j,cd];
           valuesum(k,:)=value;
       end
       k=k+1;
    end
end

The valuesum variable can be obtained through the above code. The first column of the variable stores the value of sseb, the second column is the value of ssebop, and the third column is the number of values of the two images in this interval. The scatter density map can be drawn through the scatter function, but it is rough, and the image needs to be modified. Use the following code

set(gcf,'Units','centimeters','Position',[6 6 14 13]); % Set image position and size
valuesum_sseb=valuesum(valuesum(:,3)>0,:);
scatter(valuesum_sseb(:,1),valuesum_sseb(:,2),[],valuesum_sseb(:,3),'.')
set(gca,'Xlim',[0,1100],'Ylim',[0,1100],'XTick',[0:300:1100],'YTick',[0:300:1100])
ylabel('ET_S_S_E_B_o_p_Y_R_B','Fontname', 'Times New Roman','FontSize',12); % Subscript
hold on
h1=refline(1,0) % Auxiliary 1: 1 line
h2=refline(0.3428,284.4) % Fitting line acquisition
set(h1,'color','black','linewidth',1.5)
set(h2,'color','red','linewidth',1.5)
text(100,1000,'R^2=0.51')
text(100,900,'N=798125')
text(800,100,'ET_S_S_E_B_o_p_G_l_o')

below is the example result:

example result

Please log in to leave a comment.