Annotation box left corner position
古いコメントを表示
Hi all
I have created a figure divided to 16 subplots using the commands:
hf = figure('units','normalized','outerposition',[0 0 0.5 1]); %%To adjust the aspect ratio 1:2
ha = tight_subplot(4,4,[0.045 0.025],0.05,[0.057 0.01]);%%Create the customized subplots.
ha = reshape(ha',4,4); %%ha(i,j) means subplot in column i and row j.
%%Rest of the code ...
axes(ha(i,j));
%%4 plots in every subplots
pbaspect([1 1 1]) %%To make each subplot square shape.
dim = [0,0,0.5,0.5];
annotation(hf,'textbox',dim,'String',LEGEND(5:8),'FitBoxToText','on');
My confusion is that why the specified dim above place the annotation box where it is depicted in the attached picture. If that is the position of the left corner, then what would be the actual position of the real left corner of the attached picture? My goal is to calculate the left corner position of annotation boxes programmatically and place one box in each subplot.
Thank you!

採用された回答
その他の回答 (1 件)
Alexandre Riebel
2020 年 7 月 24 日
I have a simpler solution to this question:
for i = 1:4
a(i) = subplot(2,2,i);
b(i) = annotation('textbox','String',"test",'Position',a(i).Position,'Vert','bottom','FitBoxToText','on')
end

Basically this code is just fitting a textbox to the plot area of each subplot, then ensuring that the text is in the bottom of that textbox, then resizing the textbox to fit the text. If you want the textbot at the top of the plot, switch 'bottom' to 'top' and if you want the textbox in the middle or left side of the plot use 'HorizontalAlignment'.
1 件のコメント
Amir Mohammad Alizadeh
2024 年 1 月 6 日
Thank you for this simple and practical solution.
カテゴリ
ヘルプ センター および File Exchange で Text Data Preparation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!









