Filter löschen
Filter löschen

Moving text of xline up and down and left and right

26 Ansichten (letzte 30 Tage)
Dharma Khatiwada
Dharma Khatiwada am 8 Nov. 2022
Kommentiert: Star Strider am 8 Nov. 2022
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 Kommentar
KALYAN ACHARJYA
KALYAN ACHARJYA am 8 Nov. 2022
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 8 Nov. 2022
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 Kommentare
Dharma Khatiwada
Dharma Khatiwada am 8 Nov. 2022
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 am 8 Nov. 2022
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).
.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by