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

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개)

카테고리

도움말 센터File Exchange에서 Display Image에 대해 자세히 알아보기

제품

릴리스

R2022a

질문:

2022년 6월 29일

댓글:

DGM
2022년 6월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by