Clear Filters
Clear Filters

How to put textbox in same position of the plots

15 views (last 30 days)
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.

Accepted Answer

Voss
Voss on 18 Apr 2024

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 Comments
ANANTA BIJOY BHADRA
ANANTA BIJOY BHADRA on 18 Apr 2024
Edited: ANANTA BIJOY BHADRA on 18 Apr 2024
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 on 18 Apr 2024
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!

Sign in to comment.

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!