フィルターのクリア

Moving text of xline up and down and left and right

26 ビュー (過去 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 Center および File ExchangeText Data Preparation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by