Mischa Kim is correct that starting in R2020b you can set the InnerPosition property (or PositionConstraint property) on UIAxes to solve this problem. However, there are workarounds for MATLAB R2018b and newer, and even in R2020b that may not be the best option to align to axes like you want.
As long as you are running MATLAB R2018b or newer, you can use a regular axes within App Designer, and regular axes will allow you to set the InnerPosition property to align the axes. The limitation is that you have to create the regular axes programmatically (you cannot add it to the app in design mode).
My recommendation is to replace both your UIAxes with a panel that occupies the same region as both UIAxes, then in your startup function create two axes within that panel. You have three options for aligning the axes:
- In R2019b or newer, use the tiledlayout and nexttile commands to create two axes aligned the way you like.
- In R2018b or newer, you can disable the AutoResizeChildren property on the panel, then use subplot to create two axes within the panel.
- In R2018b or newer, you can also just use the axes command and then manually position your two axes using the InnerPosition property to get them to align with one another.
Some example code, using the tiledlayout and nexttile commands, that will keep two axes aligned. This code can be run in your startup function. I'm assuming you've created a panel named Panel1 in your app, and you can create two properites in your app named Axes1 and Axes2 to store handles to your axes.
t = tiledlayout(app.Panel1, 2, 1);
app.Axes1 = nexttile(t);
app.Axes2 = nexttile(t);