How to change the size and position of subplots after defining axis handles

3 ビュー (過去 30 日間)
Corymbiamaculata
Corymbiamaculata 2022 年 3 月 14 日
回答済み: Jan 2022 年 3 月 15 日
I have a figure with eight subplots, e.g.
a = subplot(4,2,1);
In each subplot, I define the main and an underlying axis to control xticklabels, more precisely to place labels between ticks (see https://se.mathworks.com/matlabcentral/answers/593956-how-to-write-in-the-middle-of-ticks ).
% Create main axis and an underlying axis to control xticklabels.
axUnder = cla(); % Underlying axis handle
ax = copyobj(axUnder, ancestor(axUnder,'figure')); % main axis handle.
Each subplot has a line plot with datetime values on the x axis:
plot(ax,x,y);
At the end of the code, I have a section specifying the size and position of subplots, e.g.
set(a, 'Position', [0.1 0.85 0.45 0.18]);
Because of introducing the 'ax' handle earlier in the code, this section no longer works - MATLAB moves and resizes blank axes instead of my plots. Does any of you know how I can specify which axes I want to move/resize? Thank you in advance!
  4 件のコメント
Adam Danz
Adam Danz 2022 年 3 月 14 日
What is 'a' in the last block of code in your question? I see where you're defining ax and axUnder but what is 'a'?
Corymbiamaculata
Corymbiamaculata 2022 年 3 月 15 日
See the first two lines of my post :)
Anyway, Jan has already answered my question - but in a comment, so I'm not sure how I can accept it to close the thread.

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

採用された回答

Jan
Jan 2022 年 3 月 15 日
[Copied from the comments]
subplot is a wrapper for an axes command defining a specific position. If you change the position later, calling subplot is a waste of time. Just call axes() directly and define the wanted position directly.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxes Appearance についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by