How to Combine Legend Icons from Two Graphs
3 ビュー (過去 30 日間)
古いコメントを表示
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
2020 年 10 月 12 日
% if true
% code
% end
legend([f k],{'Data','fit','Confidence bounds','Alternate fit'});
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!