Thread Subject: change color when hold on

Subject: change color when hold on

From: Luca Cerone

Date: 24 Nov, 2007 16:07:51

Message: 1 of 5

Hi,
I have two questions about plots.

I have two matrix X,Y of the same size.

i need to plot curves from them and I use the following code:

plot(X(1,:),Y(1,:))
hold on

for i=2:10
plot(X(i,:),Y(i,:));
end

The problem is that all the curves have the same color,
How can I make it change???

(note: X(1,:) is different from X(i,:) that's why I don't
create a vector x and plot with plot(x,Y))

I also have a problem with plot handles,
if I make
h=plot(x,y)
plot(h,a,b)

I get the error: ??? Error using ==> plot
Data must be a single matrix Y or a list of pairs X,Y

Can anybody help me?
Thank you in advance, -Luca-

Subject: change color when hold on

From: Jerome Briot

Date: 24 Nov, 2007 18:25:41

Message: 2 of 5

Hi,

try this :

figure
hold on

col=hsv(10);
for i=1:10
    plot(X(i,:),Y(i,:),'color',col(i,:));
end

Jérôme

Subject: change color when hold on

From: Bruno Luong

Date: 24 Nov, 2007 18:38:01

Message: 3 of 5

"Luca Cerone" <cerone@to-see.it> wrote in message
<fi9i8n$65v$1@fred.mathworks.com>...
> Hi,
> I have two questions about plots.
>
> I have two matrix X,Y of the same size.
>
> i need to plot curves from them and I use the following code:
>
> plot(X(1,:),Y(1,:))
> hold on
>
> for i=2:10
> plot(X(i,:),Y(i,:));
> end
>
> The problem is that all the curves have the same color,
> How can I make it change???
>
> (note: X(1,:) is different from X(i,:) that's why I don't
> create a vector x and plot with plot(x,Y))
>
> I also have a problem with plot handles,
> if I make
> h=plot(x,y)
> plot(h,a,b)
>
> I get the error: ??? Error using ==> plot
> Data must be a single matrix Y or a list of pairs X,Y
>
> Can anybody help me?
> Thank you in advance, -Luca-

Don't confuse axis handle and curve-handle. plot requires
(optionally) first argument is axis handle.

If you want MATLAB to select automatically colors for you
(very limited number), You can plot all of them together.

h = Plot(X', Y'); % Since each data are a row of X, Y

If you want set color manually

h = Plot(X(1,:),Y(1,:),'r', X(2,:),Y(2,:), 'b', ...);

h is an array of handle h(1) is curve #1, h(2) is curve #2, ...

Next, you can change the color by

set(h(1), 'Color', 'r'); % using color code character
set(h(2), 'Color', [0 0.1 0.1]); % or using 3x1 RGB color
...

Bruno





Subject: change color when hold on

From: Luca Cerone

Date: 17 Dec, 2007 09:45:58

Message: 4 of 5

Thank to both of you,
sorry for the late answer but it's been a very busy period!

Both of your answer have been useful and clarifying!!
Thanks a lot again!

"Bruno Luong" <brunoluong@yahoo.com> wrote in message
<fi9r29$f2p$1@fred.mathworks.com>...
> "Luca Cerone" <cerone@to-see.it> wrote in message
> <fi9i8n$65v$1@fred.mathworks.com>...
> > Hi,
> > I have two questions about plots.
> >
> > I have two matrix X,Y of the same size.
> >
> > i need to plot curves from them and I use the following
code:
> >
> > plot(X(1,:),Y(1,:))
> > hold on
> >
> > for i=2:10
> > plot(X(i,:),Y(i,:));
> > end
> >
> > The problem is that all the curves have the same color,
> > How can I make it change???
> >
> > (note: X(1,:) is different from X(i,:) that's why I don't
> > create a vector x and plot with plot(x,Y))
> >
> > I also have a problem with plot handles,
> > if I make
> > h=plot(x,y)
> > plot(h,a,b)
> >
> > I get the error: ??? Error using ==> plot
> > Data must be a single matrix Y or a list of pairs X,Y
> >
> > Can anybody help me?
> > Thank you in advance, -Luca-
>
> Don't confuse axis handle and curve-handle. plot requires
> (optionally) first argument is axis handle.
>
> If you want MATLAB to select automatically colors for you
> (very limited number), You can plot all of them together.
>
> h = Plot(X', Y'); % Since each data are a row of X, Y
>
> If you want set color manually
>
> h = Plot(X(1,:),Y(1,:),'r', X(2,:),Y(2,:), 'b', ...);
>
> h is an array of handle h(1) is curve #1, h(2) is curve
#2, ...
>
> Next, you can change the color by
>
> set(h(1), 'Color', 'r'); % using color code character
> set(h(2), 'Color', [0 0.1 0.1]); % or using 3x1 RGB color
> ...
>
> Bruno
>
>
>
>
>

Subject: change color when hold on

From: Luca Cerone

Date: 17 Dec, 2007 10:53:46

Message: 5 of 5

Thank to both of you,
sorry for the late answer but it's been a very busy period!

Both of your answer have been useful and clarifying!!
Thanks a lot again!

"Bruno Luong" <brunoluong@yahoo.com> wrote in message
<fi9r29$f2p$1@fred.mathworks.com>...
> "Luca Cerone" <cerone@to-see.it> wrote in message
> <fi9i8n$65v$1@fred.mathworks.com>...
> > Hi,
> > I have two questions about plots.
> >
> > I have two matrix X,Y of the same size.
> >
> > i need to plot curves from them and I use the following
code:
> >
> > plot(X(1,:),Y(1,:))
> > hold on
> >
> > for i=2:10
> > plot(X(i,:),Y(i,:));
> > end
> >
> > The problem is that all the curves have the same color,
> > How can I make it change???
> >
> > (note: X(1,:) is different from X(i,:) that's why I don't
> > create a vector x and plot with plot(x,Y))
> >
> > I also have a problem with plot handles,
> > if I make
> > h=plot(x,y)
> > plot(h,a,b)
> >
> > I get the error: ??? Error using ==> plot
> > Data must be a single matrix Y or a list of pairs X,Y
> >
> > Can anybody help me?
> > Thank you in advance, -Luca-
>
> Don't confuse axis handle and curve-handle. plot requires
> (optionally) first argument is axis handle.
>
> If you want MATLAB to select automatically colors for you
> (very limited number), You can plot all of them together.
>
> h = Plot(X', Y'); % Since each data are a row of X, Y
>
> If you want set color manually
>
> h = Plot(X(1,:),Y(1,:),'r', X(2,:),Y(2,:), 'b', ...);
>
> h is an array of handle h(1) is curve #1, h(2) is curve
#2, ...
>
> Next, you can change the color by
>
> set(h(1), 'Color', 'r'); % using color code character
> set(h(2), 'Color', [0 0.1 0.1]); % or using 3x1 RGB color
> ...
>
> Bruno
>
>
>
>
>

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
figure Luca Cerone 24 Nov, 2007 11:10:07
plot Luca Cerone 24 Nov, 2007 11:10:07
handle Luca Cerone 24 Nov, 2007 11:10:07
hold Luca Cerone 24 Nov, 2007 11:10:07
on Luca Cerone 24 Nov, 2007 11:10:07
hold on Luca Cerone 24 Nov, 2007 11:10:07
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com