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 Center および File ExchangeCamera Views についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by