How to Combine Legend Icons from Two Graphs

3 vues (au cours des 30 derniers jours)
Connor Fitzgerald
Connor Fitzgerald le 12 Oct 2020
Commenté : VBBV le 12 Oct 2020
Hello,
I would like to show the correct legend for the "Alternative Fit". Please see code below (only last three lines of interest) and image attached and assist if possible.
figure
%Main fit graph
miniLP = scatter(n,xdiffm)
fitLP = fitlm(n,xdiffm)
f = plot(fitLP)
xlim([0 4])
hold on
m = 0.19029;
N = 4;
x = linspace(0,4,N);
y = 4.2614+m*(x);
g = plot(x,y,'r');
title(' ');
xlabel('Number of Minimum');
ylabel('x-distance in eV');
set(gca,'xtick',0:4);
%Alternative fit graph
fitLP2 = fitlm(n2,xdiffmI)
m2 = 0.072857;
x2 = linspace(0,4,N);
y2 = 4.6529+m2*x2;
k = plot(x2,y2,'--m')
%legends
legend(f, 'Data', 'Fit', 'Confidence bounds',) 'Alternate Fit'); %Would like to add this from k plot. I'm aware that the "Alternative Fit" shown in image is not referring to the correct legend icon
hold off
Thanks in advance.
  1 commentaire
VBBV
VBBV le 12 Oct 2020
% if true
% code
% end
legend([f k],{'Data','fit','Confidence bounds','Alternate fit'});

Connectez-vous pour commenter.

Réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by