- Align all plot axes in the App Designer in the Design View
- In the Code View set the PositionConstraint property to innerposition, e.g.
control inner positions of ui axes in app designer
29 views (last 30 days)
Show older comments
I have a very specific question in using app designer. The picture below shows a snapshot of part of my app. Basically I want to show a signal in the top uiaxis while show a time-frequency representation of the signal in the bottom axis.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/193255/image.png)
I'm struggling with the position control right now. Since the innerposition property is read-only, I didn't figure out a way to properly adjust the inner position so that the two x-axes could be aligned well. I've tried to play with the plotboxaspectratio property. It only worked when the two uiaxes were exactly with the same size. It failed if the sizes were different.
0 Comments
Answers (2)
Mischa Kim
on 2 Dec 2020
Hi Peng, with release 2020b you can keep plot axes aligned in App Designer. Do the following:
app.UIAxes.PositionConstraint = 'innerposition';
0 Comments
Benjamin Kraus
on 2 Dec 2020
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);
0 Comments
See Also
Categories
Find more on Vector Fields 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!