Skewed Data when Scaling axis with imagesc()

19 views (last 30 days)
When plotting 2D data I tend to default to using imagesc() due to its nice default behavior. However, I found myself very mislead with some plotted results when trying to scale the data in the axis. In the example below, I compare between pcolor() and imagesc() for scaled and unscaled y-axis data.
x=1:200;
y=1:100;
[X, Y] = meshgrid(x, y);
dummyData = (sqrt(X.^2 + Y.^2));
area = 2;
distance = 100;
nexttile
imagesc(x,y, dummyData);
set(gca,'YDir','normal')
title('Unscaled with imagesc()')
nexttile
p1=pcolor(x,y, dummyData);
p1.EdgeAlpha = .1;
title('Unscaled with pcolor()')
nexttile
imagesc(x, atand(sqrt(area./y)./distance), dummyData);
set(gca,'YDir','normal')
title('y-axis scaled with imagesc()')
nexttile
p2=pcolor(x, atand(sqrt(area./y)./distance), dummyData);
p2.EdgeAlpha = .1;
title('y-axis scaled with pcolor()')
The unscaled look identical, great!
But the scaled are not. The pcolor is the expected result. Notice how the light EdgeAlpha of the scaled pcolor() shows the streatching of the grid to accound for the non-linear axis. Is there something I'm doing wrong with imagesc()? Or is this a limitation of imagesc() since it is expecting rectilinear grid data since it is intended for displaying images?

Accepted Answer

DGM
DGM on 10 Mar 2022
Edited: DGM on 10 Mar 2022
When setting x and y inputs to imagesc() or image(), the entire x,y vectors are not used. Imagesc considers only the first and last values of x and y and creates a linear set of ticks between those values.
As to why that's the behavior, I think that the x, y parameters used by image/imagesc() are mostly intended just for placing the image within a uniform space, so they're basically just box coordinates.
A = imread('peppers.png');
B = imread('cameraman.tif');
imagesc(A); hold on
imagesc([100 300],[100 300],B)

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!