Moving text of xline up and down and left and right

36 次查看(过去 30 天)
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