x = randn(1000,1) + randn(1000,1);
y= randn(1000,1) + randn(1000,1);
X = [x,y];
N=histcounts2(x,y);
N1 = histcounts2(x,y,'Normalization','countdensity');
N2 = histcounts2(x,y,'Normalization','cumcount');
N3 = histcounts2(x,y,'Normalization','probability');
N4 = histcounts2(x,y,'Normalization','pdf');
N5 = histcounts2(x,y,'Normalization','cdf');
figure
subplot(3,3,1);
scatter(x,y, '.');
title('Scatter plot of the data');
subplot(3,3,2);
h = histogram2(x,y,'DisplayStyle','tile','ShowEmptyBins','on');
title('Density plot from the data - using histogram2');
subplot(3,3,3);
contour(N);
colorbar
title('contour plot - using histcounts2 - default normalization');
subplot(3,3,4);
contour(N1);
colorbar
title('contour plot - using histcounts2 - countdensity normalization');
subplot(3,3,5);
contour(N2);
colorbar
title('contour plot - using histcounts2 - cumcount normalization');
subplot(3,3,6);
contour(N3);
colorbar
title('contour plot - using histcounts2 - probability normalization');
subplot(3,3,7);
contour(N4);
colorbar
title('contour plot - using histcounts2 - pdf normalization');
subplot(3,3,8);
contour(N5);
colorbar
title('contour plot - using histcounts2 - cdf normalization');