How to plot multiple fitted curves in single plot with different colors and legends
2 次查看(过去 30 天)
显示 更早的评论
Hi all,
I am trying to plot multiple fitted curves in single plot using for loop. I wish to have different colors for each plot (or atleast for each fitted line) along with all legends.
Kindly help!
Thanks!
for cf = 1:3
AHG_final; % a, b and Name comes from 'AHG_final' script
loga = log(a);
fitc = fit(loga',b','poly1');
plot(fitc,loga',b');legend(['River',sprintf(' %d : ', cf), sprintf( Name)]);
xlabel('log a'); ylabel('b'); title(['River',sprintf(' %d : ', cf), sprintf( Name)]);
hold on;
end
0 个评论
回答(1 个)
Serhii Tetora
2020-7-20
You can predefine your colors for example as
colors = {'r','g','b'};
% or
colors = colormap(jet(3));
% etc.
and than in loop
h = plot(fitc,loga',b');
set(h,'Color',colors{i});
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!