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

4 ビュー (過去 30 日間)
Shweta Narkhede
Shweta Narkhede 2020 年 7 月 20 日
回答済み: Serhii Tetora 2020 年 7 月 20 日
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

回答 (1 件)

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

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by