App Designer UIAxes lock Axes when zooming with axis equal on

2 views (last 30 days)
I want to have the axis equal of the UIAxes. If i do this with 'axis equal' the problem is that when I zoom the plot the UIAxes are changing it's size. I'm zooming with the integrated tool of the plot in the upper right corner. I want it like in a normal plot with axis equal. When I zoom there the plot stays the same size.

Answers (1)

Rahul
Rahul on 25 Jun 2025
Hi Tobias,
I understand that you're trying to set 'axis equal' on a UIAxes in App Designer to maintain the correct aspect ratio, but when you zoom using the built-in toolbar, the axes change in a way that's different from the behavior in a standard MATLAB figure.
This happens because 'UIAxes' object behaves slightly differently from standard axes. In case of App Designer, 'axis equal' is integrated initially, but interactive zooming and panning can override the equal scaling due to layout management and resizing behavior.
To maintain an equal aspect ratio even after zooming, you can use the 'DataAspectRatio' property instead of relying solely on 'axis equal'. Here's how you can utilize the same in a MATLAB application:
% In your App Designer startup function or plot setup
app.UIAxes.DataAspectRatio = [1 1 1];
This tells the axes to preserve the ratio of data units in x, y, and z directions, which is equivalent to 'axis equal' and persists even during zooming or panning.
However, in MATLAB R2020b, UIAxes can still behave unexpectedly when constrained by the App layout system. To improve interactivity:
  • You can disable some automatic resizing by anchoring the 'UIAxes' size or placing it inside a fixed-size panel.
  • Alternatively, you can manually reset the aspect ratio after every zoom/pan interaction using callbacks.
For automating the above mentioned process, you can link a listener to the 'UIAxes' limits, as shown below:
addlistener(app.UIAxes, 'XLim', 'PostSet', @(src, evt) enforceAspectRatio(app));
addlistener(app.UIAxes, 'YLim', 'PostSet', @(src, evt) enforceAspectRatio(app));
function enforceAspectRatio(app)
app.UIAxes.DataAspectRatio = [1 1 1];
end
This approach ensures that even after zooming, the aspect ratio is re-applied consistently.
For more information regarding various function and parameters mentioned in the given code snippet, you can refer to the following documentation link:
Best!

Categories

Find more on Data Exploration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!