Add a Title for Each Group of Subplots in a Figure Window

17 ビュー (過去 30 日間)
Kareem Elgindy
Kareem Elgindy 2021 年 2 月 27 日
コメント済み: dpb 2021 年 2 月 28 日
Suppose I have 2 rows and 4 columns of subplots in a figure window. How can I add a title for the first row and another title for the second row?
The closest command I could think of is sgtitle, which adds title to subplot grid. I read its help documentation in MATLAB 2020b; however, none of the examples there explains how it is possible to answer my question.
  1 件のコメント
dpb
dpb 2021 年 2 月 27 日
So far there is no builtin function to add more than one title or sgtille to a figure...

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

回答 (1 件)

Image Analyst
Image Analyst 2021 年 2 月 27 日
I believe you can use text(). I think it will place text on the figure if you tell it to, instead of the current axes. Try it to see.
  6 件のコメント
Image Analyst
Image Analyst 2021 年 2 月 28 日
You have complete control over everything if you don't like the defaults. Get a handle to the axes, and then set whatever you want, like the Position property to size and locate the axes.
h1 = subplot(2, 2, 1);
h1.Units = 'normalized'
h1.Position = [0.1, 0.2, 0.4, 0.4] % or whatever.
dpb
dpb 2021 年 2 月 28 日
And, it's not really that complicated, just takes either some trial and error (or more thinking about the geometry and the algebra to generalize than I've got the time/interest to do at the moment to write more general code).
Again from the above starting point just the following
for i=5:6,hAx(i).Position(4)=hAx(i).Position(4)*0.9);end
hTtlAX=text(0.5,0.5*0.96,'New Title Axis Text','HorizontalAlignment','center');
results in
The actual height reduction of 4% off the nominal 50% midpoint of the outside encompassing axes was trial and error. The first line just reduces the height of the two plots above which want to insert the title by 10% of their default height.
Salt to suit...

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

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by