Moving text of xline up and down and left and right

조회 수: 36 (최근 30일)
Dharma Khatiwada
Dharma Khatiwada 2022년 11월 8일
댓글: Star Strider 2022년 11월 8일
Hi,
I am trying to move the text of xline in less crowded area. It can be up and down and also left and right. Your help will be appreciated.
Thanks
[maxSignal, indexOfMax] = max(F);
tMax = B(indexOfMax);
xline(tMax, 'Color', 'r', 'LineWidth', 0.8)
textLabel = sprintf('Vmax=%.2f at t=%.2f', maxSignal, tMax);
text(tMax, maxSignal, textLabel, 'fontSize', 16, 'Color','r','VerticalAlignment','bottom','HorizontalAlignment','left');
  댓글 수: 1
KALYAN ACHARJYA
KALYAN ACHARJYA 2022년 11월 8일
You can change the position of the text as needed, look at the following sample example:
x = 0:pi/20:2*pi;
y = sin(x);
plot(x,y)
text(1,0.8,'\leftarrow sin(\pi)')
%....^ ^ %Change those values and see the difference

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2022년 11월 8일
I am not certain what you want.
Try this —
x = 0:0.1:5;
y = 0.55-0.5*exp(-1.5*x);
maxSignal = 0.2;
tMax = 1;
figure
plot(x, y)
ylim([0 0.7])
textLabel = sprintf('Vmax=%.2f at t=%.2f', maxSignal, tMax)
textLabel = 'Vmax=0.20 at t=1.00'
xl = xline(tMax, '-', textLabel, 'Color', 'r', 'LineWidth', 0.8);
xl.LabelVerticalAlignment = 'top';
xl.LabelOrientation = 'horizontal';
.
  댓글 수: 2
Dharma Khatiwada
Dharma Khatiwada 2022년 11월 8일
Thank you Star Strider,
I was able to move the text up and down (not shown in the graph below). Is there a way I can move text for example Vmax=146.50 at t=36.40 to the left and right? I am trying to keep that text somewhere at the middle of the figure.
Star Strider
Star Strider 2022년 11월 8일
As always, my pleasure!
The LabelHorizontalAlignment name-value pair is the only option I see for that in the xline documentation. For a specific text object otherwise, you can put it anywhere you want (even outside the axes limits, although you need to be careful about that).
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by