How to put a label on each plotted curve
47 次查看(过去 30 天)
显示 更早的评论
Having the following code that would plot two curves on the same plot, the plot fr theoriginal data and the plot for the fitted curve that is being fitted using the function createFit. I have computed the area under the curve for both curves and i would like to put it as a label on each curve in the plot how can i possibly do that?
This is the code I am using
TestData.Date2 = datetime(string(TestData.Date), "InputFormat", "uuuuMMddHHmm");
dates = unique(TestData.Date2);
for ii = 1:20
tDate = TestData(TestData.Date2 == dates(ii), :);
Int = trapz(tDate.GDALT, tDate.NE8);
Figure=figure(ii);
plot(tDate.GDALT, tDate.NE8);
hold on
%plot( tDate.predections, tDate.GDALT, 'red');
[xData, yData] = prepareCurveData( tDate.GDALT, tDate.NE8 );
% Set up fittype and options.
ft = fittype( 'smoothingspline' );
opts = fitoptions( 'Method', 'SmoothingSpline' );
opts.SmoothingParam = 0.00121653578719157;
% Fit model to data.
[fitresult, gof] = fit( tDate.GDALT,tDate.NE8, ft, opts );
% Plot fit with data.
%figure( 'Name', 'untitled fit 1' );
Int2 = trapz(xData, yData);
h = plot( fitresult, xData, yData );
Diff=Int-Int2;
xlabel("NE8");
ylabel("GDALT");
title(string(dates(ii)));
legend({'Original','Constructed'})
end
采纳的回答
Abhishek Tiwari
2022-6-26
Hi,
One method is to choose any point on each curve and add text description to it that may serve as a label. Similarly, LineMarks can also be utilized to add text on curve.
Example:
x = -pi:0.01:pi;
y1 = cos(x);
y2 = sin(x);
plot(x,y1,'b-'); hold on
plot(x,y2,'r-'); hold off
text(x(end),y1(end),"cos(x)",'Color','blue');
text(x(end),y2(end),"sin(x)",'Color','red');
These might be useful:
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!