Effacer les filtres
Effacer les filtres

Position Constraint of Tiled Chart Layout changes automatically when setting position property

5 vues (au cours des 30 derniers jours)
Dear all,
I am creating a plot with a 1 x 4 tiled chart layout, which is a children of a figure. For printing purposes (I use "exportgraphics" or "saveas") I am trying to set the size of the figure, which works fine. Then I also want to set the size of the TiledChartLayout. However when I change the Values of the "Position" property, the "PositionConstraint" property of the "TiledChartLayout" automatically gets set to "InnerPosition", which causes the "OuterPosition" property to change from [0 0 1 1] (default) to [-0.0583 1.5e-08 1.14 0.99]. If I then set the "OuterPosition" back to [0 0 1 1], the "InnerPosition" changes back to what it was before.
Is this a bug of some sort? I know that in MATLAb documentation it says that changing the "PositionConstraint" property has no effect when the parent container is a TiledChartLayout, but in my case the parent container is a figure, so this should work.
Here is the code that I am using:
%% SET SIZE
% OUTER POSITION
set(tiled,'PositionConstraint','OuterPosition');
% INNER POSITION
size = get(tiled,'Position');
set(tiled,'Position',[0.085 size(2) 0.9 size(4)]);
So the resulting "OuterPosition" should be [0 0 1 1] and the resulting "InnerPosition" should be [0.085 0.16 0.9 0.66], but it is not, as described above.
Any help is highly appreciated.
Best regards,
Raphael

Réponses (1)

Abhinav Aravindan
Abhinav Aravindan le 23 Fév 2024
Setting the Position property of “tiledlayout defines the inner size and location, which excludes the margins for decorations such as titles and axis labels and is equivalent to setting the InnerPosition. Since the inner position is being specified, the PositionConstraint is automatically adjusted to hold the new position property constant. Consequently, the value of OuterPosition is recalculated based on the new InnerPosition to ensure that the labels, titles, and ticks are displayed correctly. A similar behavior is observed when setting the OuterPosition property.
It is to be noted that the value of the unconstrained property depends on the “Layout” property values set. For instance, setting the “OuterPosition” to [0 0 1 1] results in different “InnerPosition” values when different “Padding” is set. The below code snippet illustrates this behaviour.
clc; clear; close all;
% Figure
fig = figure;
tiled = tiledlayout(fig, 1,4);
x = linspace(0,30);
y1 = sin(x/2);
y2 = sin(x/3);
y3 = sin(x/4);
y4 = sin(x/5);
% Tile 1
nexttile
plot(x,y1)
xlabel("x1")
ylabel("y1")
% Tile 2
nexttile
plot(x,y2)
xlabel("x2")
ylabel("y2")
% Tile 3
nexttile
plot(x,y3)
xlabel("x3")
ylabel("y3")
% Tile 4
nexttile
plot(x,y4)
xlabel("x4")
ylabel("y4")
% Tiled Layout Properties
disp("Inital Values")
disp("Outer Position : " + join(string(tiled.OuterPosition)))
disp("Inner Position : " + join(string(tiled.InnerPosition)))
disp("Position : " + join(string(tiled.Position)))
disp("Position Constraint : " + join(string(tiled.PositionConstraint)))
disp(" ")
% Setting Padding to "tight"
tiled.Padding = 'tight';
set(tiled,'OuterPosition',[0 0 1 1]);
disp("Setting Padding to tight")
disp("Outer Position : " + join(string(tiled.OuterPosition)))
disp("Inner Position : " + join(string(tiled.InnerPosition)))
disp("Position : " + join(string(tiled.Position)))
disp("Position Constraint : " + join(string(tiled.PositionConstraint)))
disp(" ")
tiled.Padding = 'loose';
set(tiled,'OuterPosition',[0 0 1 1]);
disp("Setting Padding to loose")
disp("Outer Position : " + join(string(tiled.OuterPosition)))
disp("Inner Position : " + join(string(tiled.InnerPosition)))
disp("Position : " + join(string(tiled.Position)))
disp("Position Constraint : " + join(string(tiled.PositionConstraint)))
disp(" ")
Output:
For further information, please find below the relevant documentation.

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by