MATLAB: Does “imagesc” shift the shape upward when plotting density

imagescMATLAB

When I am plotting the shape representing the density it shifts upwards slightly compared to the actual shape when using "imagesc". I expect both the shapes to be on the same location on the grid. How do I fix this?

Best Answer

To resolve this set the "YDir" to "normal". By default, the 'imagesc' functions invert the y-axis direction when the image is displayed on an axes by setting the "YDir" property to "reverse". To invert the y-axis direction, set the 'YDir' property to 'normal', as follows:
load clown
clims = [10 60];
imagesc(flipud(X),clims)
colormap(gray)
set(gca,'YDir','normal')