Zooming Into UIAxes Image Changes Axis Shape and Position: Why, and How Do I Fix?!

조회 수: 7 (최근 30일)
I am developing a MATLAB App, and have an image in a UIAxes, with the following properties defined:
s1 = 512;
s2 = 512;
app.UIAxes_Image_Plot.XLim = [0,s1];
app.UIAxes_Image_Plot.YLim = [0,s2];
app.UIAxes_Image_Plot.ZLim = app.UIAxes_Image_Plot.XLim;
app.UIAxes_Image_Plot.CameraPosition = [s1/2, s2/2, s1/2];
app.UIAxes_Image_Plot.CameraTarget = [s1/2, s2/2, 0];
daspect(app.UIAxes_Image_Plot, [1 1 1])
This plots the images well, and fill the whole defined axes position. However, when I attempt to zoom in with either a click or the scroll wheel, the image and axis both shrink and change position depending on where in the image I zoom in. I feel like the issue is due to the automatic updating of the CameraPosition and/or CameraTarget but I have played around with these settings, to no avail.
I also feel like I could update the data aspect ratio by the zoom factor i.e. zoom = 2 => DataAspectRatio = [2 2 2], however I don't know how I can get the zoom factor while scrolling/clicking zoom!
All I want is to be able to zoom into the image without the axis changing its shape or position within the figure window.
Thanks!

채택된 답변

Adam Danz
Adam Danz 2023년 3월 10일
편집: Adam Danz 2023년 3월 10일
Your intuitions are correct. Panning and zooming reset the CameraPosition and CameraTarget back to default states which explain the change in axis view that happens after panning or zooming.
One workaround is to control zoom by setting axis limits and/or camera viewing ange (camva).
Another workaround that I haven't tested is to use the LimitsChangedFcn, a callback function in the axis rulers, to reset the camera position and target after pan/zoom interactions. This function responds to changes to axis limits. However, this may have unintended consequences since these interactions may change the camera position and target so I'm not sure how you would update those camera properties in the callback function.
  댓글 수: 5
Adam Danz
Adam Danz 2023년 3월 10일
I've had the same experience. gcf works if,
uifigure('HandleVisibility','on')
gcf()
Scott Young
Scott Young 2023년 3월 13일
Thanks very much, Adam. I'm sure this would work, however I was able to eliminate the need for the CameraPosition and CameraTarget parameters: I originally wanted the image to occupy the entire axis and, months ago, discovered you could do that with the camera parameters, but I have since learned it's far easier to just set the OuterPosition equal to the InnerPosition in the UIAxes: this allows for the easy use of the zoom functions.
Thanks again!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Camera Views에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by