Why does the "UIAxes" property "PositionConstraint" reset on its own to "outerposition" in a multiple axes setup after I explicitly set it to "innerposition"?

4 visualizzazioni (ultimi 30 giorni)

I am working with a UI that has multiple "UIAxes" objects and aligning them by setting the "PositionConstraint" property to "innerposition". However, when the "UIAxes" are plotted, this property seems to reset itself to "outerposition" for some of the "UIAxes" objects, for no apparent reason.
Why does this happen and how do I resolve it?

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 15 Mar 2024
The axes are being created as a child of a "Figure" object that has the "AutoResizeChildren" property enabled. There are two related problems with this system:
  1. "AutoResizeChildren" is incapable of aligning axes using the "InnerPosition". "AutoResizeChildren" will only ever operate by setting the "OuterPosition" of the axes and setting the "OuterPosition" of the axes will toggle the "PositionConstraint" property to "outerposition".
  2. "AutoResizeChildren" works by setting a new "OuterPosition" on the axes whenever the "Figure" (or immediate container of the axes) is resized. Therefore, any time you resize the figure (or immediate container of the axes), the "PositionConstraint" of the axes will be toggled to "outerposition", regardless of its previous value.
"AutoResizeChildren" was never designed to keep axes aligned with one another, and it makes no attempts at doing that. By setting "PositionConstraint" to "outerposition", it is informing the user that because you are using "AutoResizeChildren", your request to use "PositionConstraint" of "innerposition" is not being honored.
Please note that if your goal is to keep two axes aligned with each other, you have a few options:
  1. SIMPLEST APPROACH: Put both axes into a "Panel" (or another container) with the "AutoResizeChildren" property disabled. Then you can use a "PositionConstraint" of 'innerposition' and it should work as you would expect. You can also just disable "AutoResizeChildren" on the top-level figure.
  2. PREFERRED APPROACH: Put both axes into a 1x1 "tiledlayout". "tiledlayout" was designed with the intention of aligning the inner position of multiple axes with each other. The traditional use-case is to have a grid of Axes, but "tiledlayout" also works just as well to keep two axes that are in the same tile aligned with one another. You can put a "tiledlayout" directly in a "uifigure", or within a "Panel" or another container, then put the two axes within the "tiledlayout", and the "tiledlayout" will make sure they stay aligned with one another. Please refer to the following documentation for further information on the "tiledlayout" function: https://www.mathworks.com/help/matlab/ref/tiledlayout.html
  3. MOST CONTROL APPROACH: Disable "AutoResizeChildren" and instead use a "SizeChangedFcn" function on the container to run a function whenever the container size changes, and then use this function to do whatever layout of the axes you want.

Più risposte (0)

Categorie

Scopri di più su Labels and Annotations in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by