get handle of subplot?

185 ビュー (過去 30 日間)
Leor Greenberger
Leor Greenberger 2011 年 9 月 26 日
コメント済み: Benoit Espinola 2019 年 5 月 31 日
After I subplot, how can I get the Position property of the current axis so I can adjust it?

採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 9 月 26 日
handle=subplot(311);
get(handle,'position')
  2 件のコメント
Leor Greenberger
Leor Greenberger 2011 年 9 月 26 日
ok, I had a feeling that would be the answer. I thought you could get around having to assign a variable to the subplot.
Benoit Espinola
Benoit Espinola 2019 年 5 月 31 日
For the record, get(handle, 'position') returns a vector as such:
[a b c d]
Where
a = x_lowerLeftCorner
b = y_lowerLeftCorner
c = width
d = height
All of that in the same units.
From my understanding, when the units are 'normalized' then x = 0, y = 0 is the lower left corner of the figure and x = 1, y = 1 is the upper right corner.
So, if you want your subplot to be on the top left corner, you need to do the following:
handle=subplot(311);
c = get(handle,'position');
newPosition = [1-c(3) 1-c(4) c(3) c(4)];
newUnits = 'normalized';
set(handle,'Position', newPosition,'Units', newUnits);
If you want the subplot to be in the center of the figure alinged with its own center:
handle=subplot(311);
c = get(handle,'position');
newPosition = [(1-c(3))/2 (1-c(4))/2 c(3) c(4)];
newUnits = 'normalized';
set(handle,'Position', newPosition,'Units', newUnits);
Does it make sense?

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 9 月 26 日
get(gca,'Position')
Be careful, though: if you adjust the position such that it would overlap the normal position of a subplot that you subplot() later, then MATLAB will detect the overlap and will remove the plot being overlapped. It may be advised to subplot() all of the portions first, recording the handles, and then to go through the saved handles and reposition or resize as desired.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by