Label each line from plot automatically

30 ビュー (過去 30 日間)
Roger Gomila
Roger Gomila 2020 年 4 月 1 日
コメント済み: Ameer Hamza 2020 年 4 月 2 日
I have the following plot generated by the curve fitting tool application
I would like to instead of having the legend, to plot the labels on top of each line in a given x value (for example x = 7). I have seen people use the text() command, but I would like to know if there's any "automatic" way of doing it and avoid having to write all the exact points.
The code I use to plot one line is the following:
x = 1.5; %linewidth
set(p,'linewidth',x);
p = plot(fitresult{5},'b');
Thanks

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 4 月 1 日
Somethis like this
t = linspace(0,10, 100)';
y = sqrt(t).*linspace(1,1.5,5);
idx = find(t > 7, 1);
text_x = repmat(t(idx), 1, size(y,2));
text_y = y(idx, :);
labels = {'label1', 'label2', 'label3', 'label4', 'label5'};
plot(t,y)
hold on
t = text(text_x, text_y, labels, 'Color', 'k');
  2 件のコメント
Roger Gomila
Roger Gomila 2020 年 4 月 2 日
I understand what you did there but i do not have a common x axis, therefore i use
[xData, yData] = prepareCurveData( x_B3_NOV_2019_2, y_B3_NOV_2019_2 );
[fitresult{1}, gof(1)] = fit( xData, yData, ft, opts );
and obtain a xData, yData for each of the 6 fitresults{} i have.
I am facing trouble fith the plotting as that fitresults{}.
Ameer Hamza
Ameer Hamza 2020 年 4 月 2 日
Can you show an example of your plotting code?

サインインしてコメントする。

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by