How to plot multiple fitted curves in single plot with different colors and legends
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Serhii Tetora
on 20 Jul 2020
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 Comments
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!