Update axes position properly

4 ビュー (過去 30 日間)
susana
susana 2017 年 11 月 6 日
コメント済み: susana 2017 年 11 月 10 日
I have a GUI that has 2 options on the toolbarmenu. User may change the width of the axes or change the "template display", e.g. change the axes position. No problms if I change the width and then change the template display. But,if I change the template display first(initially I have: axes A, position 1; Axes B, position 2; Axes C, Position 3 - change to- axes A, position 3; Axes B, position 2; Axes C, Position 1) and then I change the width of the axes, the axes just deformat. I think the update of the position is not done properly. Can anyone help me? I have attached a piece of the code

採用された回答

Robert
Robert 2017 年 11 月 6 日
When you create your three axes (titled A, B, and C) they appear from right to left across the figure and in reverse order (C, B, A) in the handle array allax. Therefore they appear in allax in right-to-left order. Your function assumes this when adjusting the widths of these axes. You wrote:
[~,B]= min(X);
set(allax(B),'Position',[Pos{B,1}(1), Pos{B,1}(2), NW, Pos{B,1}(4)]);
for i=1:num-1
set(allax(i),'Position',[Pos{i,1}(1)-(num-i)*(Pos{i,1}(3)-NW), Pos{i,1}(2), NW, Pos{i,1}(4)]);
end
which works before the axes order is changed. But when you reorder the axes on the figure, your expression for the position of each axes no longer behaves properly.
The good news: the fix is easy! You can get the order by sorting the x coordinates of the axes positions and use that to put them in the expected order in the for loop. Try replacing the lines above with:
[~, order] = sort(X); % allax(order) are in order from right to left
for i = 1:num
pos = Pos{order(i)};
% shift to the left by the difference in the old widths and the new
pos(1) = pos(1) - (i-1) * (pos(3) - NW);
% set new width
pos(3) = NW;
% apply changes
set(allax(order(i)), 'Position', pos);
end
  2 件のコメント
Robert
Robert 2017 年 11 月 6 日
Additionally, you might consider using 'OuterPosition' in place of 'Position' to avoid overlap of the axes and their labels.
susana
susana 2017 年 11 月 10 日
Robert, Excellent help. Thank you very much:)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by