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

11 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

Adam Danz
Adam Danz am 10 Mär. 2023
Bearbeitet: Adam Danz am 10 Mär. 2023
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 Kommentare
Adam Danz
Adam Danz am 10 Mär. 2023
I've had the same experience. gcf works if,
uifigure('HandleVisibility','on')
gcf()
Scott Young
Scott Young am 13 Mär. 2023
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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Visual Exploration finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by