Skewed Data when Scaling axis with imagesc()

10 ビュー (過去 30 日間)
Michael Shagam
Michael Shagam 2022 年 3 月 10 日
編集済み: DGM 2022 年 3 月 10 日
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?

採用された回答

DGM
DGM 2022 年 3 月 10 日
編集済み: DGM 2022 年 3 月 10 日
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)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by