Assigning colors to different lines in one plot

Hello,
I am currently working on some code to create and format subplots. Would anybody be able to help with the following problem: a portion of my code is designed to create a subplot with 3 lines in the single plot (6:2:10). How can I go about assigning a color to each of these lines? Below is the section of my code attempting to run this command
figure(2), Colors = ['r', 'g', 'b']; c=1; subplot(121), hold on, %this makes a subplot and plots every other column from 6-10 for i = [6:2:10] plot(data(6:end,i), 'Color',[0.36 0.0 0.0]); c=c+1; end

回答 (2 件)

Image Analyst
Image Analyst 2015 年 7 月 1 日

2 投票

If you want, you can change the default color order, like in my attached demo.

1 件のコメント

Walter Roberson
Walter Roberson 2019 年 6 月 9 日
Jedidiah Tsai comments to Image Analyst:
Very helpful to me :D

サインインしてコメントする。

Chad Greene
Chad Greene 2015 年 6 月 30 日

0 投票

You're on the right track. Here's how I'd do it.
data = rand(10);
Colors = rgb('red','green','blue');
c = 1;
subplot(121)
hold on
for k = 6:2:10
plot(data(6:end,k),'color',Colors(c,:),'linewidth',2)
c = c+1;
end
legend('red data','green data','blue data')

1 件のコメント

Chad Greene
Chad Greene 2015 年 6 月 30 日
Above I'm using the rgb function which you can download from FEX. It gives rgb values of just about any color you can name.

サインインしてコメントする。

質問済み:

2015 年 6 月 30 日

コメント済み:

2019 年 6 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by