Centering annotation over subplot?

23 ビュー (過去 30 日間)
BionicLimb
BionicLimb 2019 年 11 月 5 日
コメント済み: Jess Lovering 2019 年 11 月 12 日
I'm trying to center a textbox annotation over a subplot. I have a 2x2 subplot and I want titles over the columns, centered for each column. I don't want to just use title() because it shrinks the axes of the upper plots, so they are not the same as the axes on the bottom row.
I've tried using the x position of the upper subplot like so:
figure();
hLF1 = subplot(2,2,1); bxA = boxplot([1:10;1:10]','labels',{'On','Off'}); ylabel('LabelY')
annot_LF_pos = [mean(hLF1.Position([1,3])), 0.775, 0.3, 0.2];
annotation('textbox',annot_LF_pos,'String','Title','EdgeColor','none',...
'FontSize',22,'HorizontalAlignment', 'center')
But that didn't really center it. I know I can hack around with numbers, but I'm hoping for a better solution.
I'm not tied to using an annotation, so any other suggestions are welcome!
Thanks!

採用された回答

Jess Lovering
Jess Lovering 2019 年 11 月 5 日
編集済み: Jess Lovering 2019 年 11 月 5 日
You could try to use text instead and use the x and y limits instead of the axis position, see below:
text((max(hLF1.XLim)-min(hLF1.XLim))/2+min(hLF1.XLim),max(hLF1.YLim),'Title','EdgeColor','none',...
'FontSize',22,'HorizontalAlignment', 'center','VerticalAlignment','Bottom')
  2 件のコメント
BionicLimb
BionicLimb 2019 年 11 月 7 日
That did it! Thanks.
Jess Lovering
Jess Lovering 2019 年 11 月 12 日
Happy to help!

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

その他の回答 (0 件)

カテゴリ

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