Axis resizes inconsistently in a TiledChartLayout when you change its TileSpan

13 ビュー (過去 30 日間)
Matt J
Matt J 2021 年 4 月 20 日
コメント済み: Matt J 2021 年 4 月 28 日
In the first example below, I obtain a TiledChartLayout in which all the plots have the same size (which is what I want). Why does this not remain true in the second case?
%% First Case
figure(1)
tiledlayout(2,3)
clear ax
for i=[1,2,3,5,6]
ax(i)=nexttile(i);
plot(1:5); axis square
end
ax(1).Layout.TileSpan=[2,1];
%% Second Case
figure(2);
tiledlayout(2,3)
clear ax
for i=[1,2,3,4,6]
ax(i)=nexttile(i);
plot(1:5); axis square
end
ax(4).Layout.TileSpan=[1,2];

採用された回答

Matt J
Matt J 2021 年 4 月 28 日
Here is the response from Tech Support:
After discussing with my colleagues, I was able to find a solution for the issue you are facing. This is due to an odd quirk with how "axis square" behaves.
The "axis square" command sets the "PlotBoxAspectRatio" of the axes to [1 1 1], which tells the axes that it's height and width should be equal.
When you set the "PlotBoxAspectRatio", it becomes possible for the value of the "Position" (or "InnerPosition") property on the axes to differ from the actual location of the white portion of the axes. This is odd, but expected behavior.
When in this configuration, the axes will grow as big as possible while remaining square. This means that an individual axes will meet one of three criteria:
  1. The white part of the axes is filling the height of the Position, but to remain square the width is smaller than the Position.
  2. The white part of the axes is filling the width of the Position, but to remain square the height is smaller than the Position.
  3. The aspect ratio of the Position is exactly equal to the desired aspect ratio, in which case both height and width will fill the Position.
In both blocks of code, the "Positions" ("InnerPosition") of the axes are all aligned as expected.
However in the [second] block of code:
  • axes 1, 2, 3, and 6 are all constrained in their width, so the height is smaller than the available space.
  • axes 4 on the other hand has twice the width, so it is constrained in its height, so the width is smaller than the available space.
In the second block of code all 5 axes are constrained in width, so they are all the same height and width.
To sum it up, the behavior you are seeing is expected and due to the constrained aspect ratio of the plots. Sometimes the plots will be constrained by tile width, and sometimes by height. Resizing the figure might help getting a better understanding of the feature.
I apologize for any inconvenience you faced and I hope this was helpful. I will be closing this case for now. Should you have any further questions related to the case, please do not hesitate to reach out again, and I would be happy to assist you further.
Sincerely,
Siddharth Dharm
MathWorks Technical Support Department
  1 件のコメント
Matt J
Matt J 2021 年 4 月 28 日
Resizing the figure might help...
Indeed:
t=tiledlayout(2,3);
t.TileSpacing='compact';
t.Units='points';
t.OuterPosition=[0,0,670,250]*0.7;
clear ax
for i=[1,2,3,4,6]
ax(i)=nexttile(i);
plot(1:5); axis square
end
ax(4).Layout.TileSpan=[1,2];

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by