imshow breaks after changing uiaxes limits

6 ビュー (過去 30 日間)
Andrew Estrada
Andrew Estrada 2022 年 6 月 29 日
コメント済み: DGM 2022 年 6 月 29 日
I wanted to plot a figure and then replace it with an image at a later time. The following code runs perfectly fine:
ax = uiaxes;
currentimage = imread(imagepath);
imshow(currentimage, 'Parent', ax);
but as soon as i try to change the limits of one of the axes before showing the image
ax.XLim = [0.002 .02];
the figure doesn't show. I just have a blank figure window.
One workaround is to not use uiaxes (just using ax = axes works fine), but I was working on an app in AppDesigner so it would be nice. Another I thought might be to just hide the axes and create new ones? Either way it was frustrating working out how one little change broke my program...
Is this a bug? What's happening?

採用された回答

DGM
DGM 2022 年 6 月 29 日
編集済み: DGM 2022 年 6 月 29 日
You're specifying that the axes limits should be outside of the image region.
currentimage = imread('cameraman.tif');
hi = imshow(currentimage);
hi.XData % this is the Xrange of the image data
ans = 1×2
1 256
ax = gca;
ax.XLim = [0.002 .02]; % but this is where the axis limits are
You can explicitly specify the extent of the image in the call to imshow() by including 'xdata' and 'ydata' parameters. See the documentation for imshow() for more details. Bear in mind that the aspect ratio is 1 when using imshow(), so even if you set the xdata for the image to [0.002 0.2], you'll wind up trying to plot an image that's 1280 times as tall as it is wide. It will likely be so narrow that it simply isn't visible. You'll have to pay attention to both x and y limits if you want to keep the image in-axes and viewable.
  2 件のコメント
Andrew Estrada
Andrew Estrada 2022 年 6 月 29 日
The most annoying thing is I've had an issue like this (someone else had posted about) with a similar answer in the past. Thanks!
DGM
DGM 2022 年 6 月 29 日
That's a familiar feeling. :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by