How to Combine Legend Icons from Two Graphs

조회 수: 3 (최근 30일)
Connor Fitzgerald
Connor Fitzgerald 2020년 10월 12일
댓글: VBBV 2020년 10월 12일
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
VBBV
VBBV 2020년 10월 12일
% if true
% code
% end
legend([f k],{'Data','fit','Confidence bounds','Alternate fit'});

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by