Be sure to read the documentation of imagesc. The first two inputs, if specified, are used to create the X and Y axes on the plot. However, the function uses ONLY the first and last element of each and linearly interpolates between them. Therefore, you got a linear scale from -1 to 7 for both dimensions. To fix this problem, the axis inputs to imagesc should really be generated directly from the output of hist3, so the bins in your images are identical to the bins from your histogram.
X = [-1 -5 3 6 -1 7];
Y = [-1 -6 3 6 -1 7];
[N,b] = hist3([X', Y'],[numel(X) numel(X)]);
figure
imagesc(b{1}([1 end]),b{2}([1 end]),N);
colorbar
axis xy equal tight
Note that
axis xy
ensures that the Y axis points up. imagesc expects data in image ij format, which is why the histogram axis was upside down previously.
I also suspect you may want to more carefully define the bins for your histogram as right now the Y bins are slightly larger than your X bins. You should be able to figure this out from the documentation for hist3 if you'd like to change that.
Hope that helps!
Best Answer