How to put a label on each plotted curve

49 visualizaciones (últimos 30 días)
Manar Anwar
Manar Anwar el 22 de Jun. de 2022
Respondida: Abhishek Tiwari el 26 de Jun. de 2022
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

Respuesta aceptada

Abhishek Tiwari
Abhishek Tiwari el 26 de Jun. de 2022
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:

Más respuestas (0)

Categorías

Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by