How to Combine Legend Icons from Two Graphs
3 views (last 30 days)
Show older comments
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 Comment
VBBV
on 12 Oct 2020
% if true
% code
% end
legend([f k],{'Data','fit','Confidence bounds','Alternate fit'});
Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!