フィルターのクリア

How to put textbox in same position of the plots

15 ビュー (過去 30 日間)
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA 2024 年 4 月 18 日
コメント済み: Voss 2024 年 4 月 18 日
I have two plot in a same figure. I need to set text box containing '(a)' and '(b)' in the plots. I can just put them using Insert command but I need the text box to be in the same position of their respective plot (e.g.-bottom left). I have already used legend command once to define the graphs inside the plot. What command and code can I use for this. The code to generate the figure is:
t2=0:0.001:2
a=1*sin(2*pi*5*t2)
b=0.5*sin(2*pi*5*t2)
t = tiledlayout(1,2,'TileSpacing','Compact','Padding','compact');
nexttile
plot(t2,a,'g',LineWidth=5)
legend('First wave')
ylim([-3 3])
ax = gca;
ax.GridLineWidth = 1.5;
ax.GridLineStyle = '--';
ax.GridAlpha = 0.9;
ax.LineWidth=4;
ax.FontWeight = 'bold';
nexttile
plot(t2,b,'r-.')
legend('Second wave')
ylim([-3 3])
ax = gca;
ax.GridLineWidth = 1.5;
ax.GridLineStyle = '--';
ax.GridAlpha = 0.9;
ax.LineWidth=4;
ax.FontWeight = 'bold';
I have attached a image to have the better understanding of my requirement.

採用された回答

Voss
Voss 2024 年 4 月 18 日

You asked this question a month ago, and I answered it at that time:

https://www.mathworks.com/matlabcentral/answers/2096466-how-to-align-textbox-in-matlab-plot#answer_1427841

Just change the texts' Positions to be something like 0.1,0

  2 件のコメント
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA 2024 年 4 月 18 日
編集済み: ANANTA BIJOY BHADRA 2024 年 4 月 18 日
The issue is that the plots are now different. The plots themselves can not be put in a loop. I have to put them seperately.
Voss
Voss 2024 年 4 月 18 日
You could put them in a loop, but that doesn't matter.
Just make two text calls:
t2=0:0.001:2;
a=1*sin(2*pi*5*t2);
b=0.5*sin(2*pi*5*t2);
t = tiledlayout(1,2,'TileSpacing','Compact','Padding','compact');
nexttile
plot(t2,a,'g',LineWidth=5)
legend('First wave')
ylim([-3 3])
ax = gca;
ax.GridLineWidth = 1.5;
ax.GridLineStyle = '--';
ax.GridAlpha = 0.9;
ax.LineWidth=4;
ax.FontWeight = 'bold';
text(0.02,0.01,'(a)', ...
'Units','normalized', ...
'VerticalAlignment','bottom', ...
'FontWeight','bold')
nexttile
plot(t2,b,'r-.')
legend('Second wave')
ylim([-3 3])
ax = gca;
ax.GridLineWidth = 1.5;
ax.GridLineStyle = '--';
ax.GridAlpha = 0.9;
ax.LineWidth=4;
ax.FontWeight = 'bold';
text(0.02,0.01,'(b)', ...
'Units','normalized', ...
'VerticalAlignment','bottom', ...
'FontWeight','bold')
If this answer solves the problem, please "Accept" it. Thanks!
If that other answer worked for that other question, please go ahead and "Accept" that one too. Thanks!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by