- Before plotting, save the original read-only 'InnerPosition' values
- Do your plotting
- Calculate the difference between the new inner position and old inner position
- Change the 'Position' value so that the inner position matches what it used to be.
How to stop App Designer resizing UIAxes?
27 views (last 30 days)
I have created a simple APP using the App Designer. It plots a simple graph into an UIAxes object. The problem is that the position of y-axis is moved based on the width of y-labels. In the future the APP will consist of several axes that should be perfectly aligned with the same width of x-axis. See the picture bellow:
I would like to maintain the same position of both the x-axis and y-axis not taking into account the width of the labels. It works when the program is build in GUIDE, however, I would like to make it in App Designer. Is it possible?
See the picture bellow for how it works in GUIDE and what I would like to achieve in App Designer:
Adam Danz on 23 Mar 2019
Edited: Adam Danz on 25 May 2022
Ideally you would save the inner position of the axis, do the plotting, and then restore the inner axis position. But the 'InnerPosition' property of axes in app designer is read-only (why!?? who knows). So here's a work around.
In your plotting function,
axInnerPos = app.UIAxes.InnerPosition; %1) store original inner position of axis
% plot() %2) do your plotting, etc.
innerPosDiff = axInnerPos - app.UIAxes.InnerPosition; %3) calculate difference between original and current inner ax pos.
app.UIAxes.Position = app.UIAxes.Position + innerPosDiff; %4) change the 'position' so inner position matches original values
Update: See Mischa Kim's comment below for MATLAB R2020b and later.