How do I write a line for adding a text to my plot?

20 ビュー (過去 30 日間)
Ekaterina Bikovtseva
Ekaterina Bikovtseva 2021 年 11 月 4 日
編集済み: Dave B 2021 年 11 月 4 日
Hi,
I am trying to add a text to my plot. I tried adding the following line to the code: text('k=28');
I also tried: txt= 'k=28';
Both lines didn't add the text , I am atatching my existing code below. This code is part of the function file.
fig = figure('position', utilities.centerFigPos(1500, 1200));
set(fig, 'Color', 'white', 'defaultLineLineWidth', 2, 'defaultAxesFontSize', 24);
ax = axes(fig);
scatter(ax,X,Y,'o');
line(ax, xFit, yFit);
ax.Title.String = 'Data';
ax.XScale = 'linear';
ax.YScale = 'log';
ax.XLim = [0,1];
ax.YLim = [yMin,1];
ax.YDir = 'reverse';

回答 (1 件)

Dave B
Dave B 2021 年 11 月 4 日
編集済み: Dave B 2021 年 11 月 4 日
The text function requires x and y values (or x, y, z values).
Alternatively, use the title function if you want a title for your plot (I see you already found this by setting the Title.String property)
scatter(randn(100,1),randn(100,1))
text(2,2,"k=28")
title("My Plot")

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by