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 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