Label each line from plot automatically

34 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Annotations 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by