필터 지우기
필터 지우기

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 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