How to put textbox in same position of the plots

24 次查看(过去 30 天)
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
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 CenterFile Exchange 中查找有关 Annotations 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by