Moving text of xline up and down and left and right
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dharma Khatiwada
el 8 de Nov. de 2022
Comentada: Star Strider
el 8 de Nov. de 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 comentario
KALYAN ACHARJYA
el 8 de Nov. de 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
Respuesta aceptada
Star Strider
el 8 de Nov. de 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)
xl = xline(tMax, '-', textLabel, 'Color', 'r', 'LineWidth', 0.8);
xl.LabelVerticalAlignment = 'top';
xl.LabelOrientation = 'horizontal';
.
2 comentarios
Star Strider
el 8 de Nov. de 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).
.
Más respuestas (0)
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!