Thread Subject: plot in different colors

Subject: plot in different colors

From: stat

Date: 25 Nov, 2009 10:31:03

Message: 1 of 4

Hello all,
I have X and Y 2 vectors and I want to plot(X,Y,'o') but with each 'o' having a different color, is it possible ?
As an information length(X) have non constant value but is never very big (let say 50 at most)
Thanks If you can help

statquant

Subject: plot in different colors

From: Herve

Date: 26 Nov, 2009 07:34:03

Message: 2 of 4

You could define yourself a RGB table... and then plot individually each point.
Note that I have only entered 20 colors in the RGB table...

%%%%%%%%%%%%%%%%%%%%%%%%%%%
function your_function(x,y)

ColorSet = [
0.00 0.00 1.00 % Data 1 - blue
0.00 1.00 0.00 % Data 2 - green
1.00 0.00 0.00 % Data 3 - red
0.00 1.00 1.00 % Data 4 - cyan
1.00 0.00 1.00 % Data 5 - magenta
0.75 0.75 0.00 % Data 6 - RGB
0.25 0.25 0.25 % Data 7
0.75 0.25 0.25 % Data 8
0.95 0.95 0.00 % Data 9
0.25 0.25 0.75 % Data 10
0.75 0.75 0.75 % Data 11
0.00 0.50 0.00 % Data 12
0.76 0.57 0.17 % Data 13
0.54 0.63 0.22 % Data 14
0.34 0.57 0.92 % Data 15
1.00 0.10 0.60 % Data 16
0.88 0.75 0.73 % Data 17
0.10 0.49 0.47 % Data 18
0.66 0.34 0.65 % Data 19
0.99 0.41 0.23 % Data 20
];

if length(x)-length(y) ~= 0
    error('X and Y must have the same size')
end

for i=1:length(x)
    plot(x(i),y(i),'Color',ColorSet(i,:),'Marker','o')
    hold on
end

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%

Subject: plot in different colors

From: Herve

Date: 26 Nov, 2009 07:40:07

Message: 3 of 4

In each loop, you define a new RGB color.
In this exemple, you go from black [0 0 0] to white [1 1 1].
Change ColorSet2 if you need better colors.

%%%%%%%%%%%%%%%%%%%%%%%%%%
function your_function_2(x,y)

if length(x)-length(y) ~= 0
    error('X and Y must have the same size')
end

for i=1:length(x)
    ColorSet2 = [0+i/length(x) 0+i/length(x) 0+i/length(x)];
    plot(x(i),y(i),'Color',ColorSet2,'Marker','o')
    hold on
end

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Subject: plot in different colors

From: Lorenzo Guerrasio

Date: 26 Nov, 2009 10:56:03

Message: 4 of 4

color_table=[linspace(0.1,0.9,100)',rand(100,1),rand(100,1)];%this is just random %colors you can make your own color_table for better colors.

x=rand(50,1);
scatter(x,y,20,color_table(1:length(x),:))y=rand(50,1);

"stat " <statquant@gmail.com> wrote in message <hej117$dqd$1@fred.mathworks.com>...
> Hello all,
> I have X and Y 2 vectors and I want to plot(X,Y,'o') but with each 'o' having a different color, is it possible ?
> As an information length(X) have non constant value but is never very big (let say 50 at most)
> Thanks If you can help
>
> statquant

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
scatter Lorenzo Guerrasio 26 Nov, 2009 05:59:10
random color stat 25 Nov, 2009 05:34:06
plot stat 25 Nov, 2009 05:34:06
color stat 25 Nov, 2009 05:34:06
rssFeed for this Thread

Contact us at files@mathworks.com