How to plot multiple fitted curves in single plot with different colors and legends

4 views (last 30 days)
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

Answers (1)

Serhii Tetora
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});

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!