I am trying to plot the point density for a large set of points (see image). How would you do it? I tried using the code below, but I got the error Error using griddedInterpolant
The grid vectors are not strictly monotonic increasing
(I guess because the points are not ordered).
%# bin centers (integers)
xbins = floor(min(X)):step_for_plot:ceil(max(X));
ybins = floor(min(Y)):step_for_plot:ceil(max(Y));
xNumBins = numel(xbins);
yNumBins = numel(ybins);
%# map X/Y values to bin indices
Xi = round( interp1(xbins, 1:xNumBins, X, 'linear', 'extrap') );
Yi = round( interp1(ybins, 1:yNumBins, Y, 'linear', 'extrap') );
%# limit indices to the range [1,numBins]
Xi = max( min(Xi,xNumBins), 1);
Yi = max( min(Yi,yNumBins), 1);
%# plot 2D histogram
imagesc(xbins, ybins, Data), axis on %# axis image
colormap hot; colorbar
hold on, plot(X, Y, 'b.', 'MarkerSize',1), hold off