Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to change color for multiple data sets plotted on one graph

Subject: how to change color for multiple data sets plotted on one graph

From: Natasha

Date: 14 Dec, 2012 00:26:22

Message: 1 of 4

I have a script that allows you to change one variable manually. Each time you do so and plot the outcome, a new line forms. How can I make it so that each new line is a new color (or alternating colors)?

What I have:
figure (1)
plot(r,w1)


I'm very new to matlab, and teaching myself. I've tried several codes involving 'color' but do not know how to write it properly, any help would be appreciated.

Thanks

Subject: how to change color for multiple data sets plotted on one graph

From: Greg Heath

Date: 14 Dec, 2012 02:03:09

Message: 2 of 4

"Natasha" wrote in message <kadrne$ibm$1@newscl01ah.mathworks.com>...
> I have a script that allows you to change one variable manually. Each time you do so and plot the outcome, a new line forms. How can I make it so that each new line is a new color (or alternating colors)?
>
> What I have:
> figure (1)
> plot(r,w1)
>
>
> I'm very new to matlab, and teaching myself. I've tried several codes involving 'color' but do not know how to write it properly, any help would be appreciated.

figure(2)
hold on
plot(x,y1,'b')
plot(x,y2,'g')
plot(x,y3,'r')
etc

Hope this helps. Also see

help plot

doc plot

Greg

Subject: how to change color for multiple data sets plotted on one graph

From: dpb

Date: 14 Dec, 2012 15:51:40

Message: 3 of 4

On 12/13/2012 8:03 PM, Greg Heath wrote:
> "Natasha" wrote in message <kadrne$ibm$1@newscl01ah.mathworks.com>...
>> I have a script that allows you to change one variable manually. Each
>> time you do so and plot the outcome, a new line forms. How can I make
>> it so that each new line is a new color (or alternating colors)?
>>
>> What I have: figure (1)
>> plot(r,w1)
>>
>>
>> I'm very new to matlab, and teaching myself. I've tried several codes
>> involving 'color' but do not know how to write it properly, any help
>> would be appreciated.
>
> figure(2)
> hold on
> plot(x,y1,'b')
> plot(x,y2,'g')
> plot(x,y3,'r')
> etc
>
> Hope this helps. Also see
>
> help plot
>
> doc plot
...

And, to make it slightly more general, make up a colors vector of the
entries in the predefined list

colors={'b';'g';'r'; ... }; % fill in rest of list in lieu of ...
plot(x,y(i),colors{i}) % i is a variable index in your loop, say

NB since colors is cell array, use the {} to dereference it. Or, it
could be a character array since is one character, but if then wanted to
add a line character to be more than a single character have to address
it as the 2D array instead of the single cell index.

--

Subject: how to change color for multiple data sets plotted on one graph

From: Natasha

Date: 17 Dec, 2012 00:55:08

Message: 4 of 4

dpb <none@non.net> wrote in message <kafhtk$rht$1@speranza.aioe.org>...
> On 12/13/2012 8:03 PM, Greg Heath wrote:
> > "Natasha" wrote in message <kadrne$ibm$1@newscl01ah.mathworks.com>...
> >> I have a script that allows you to change one variable manually. Each
> >> time you do so and plot the outcome, a new line forms. How can I make
> >> it so that each new line is a new color (or alternating colors)?
> >>
> >> What I have: figure (1)
> >> plot(r,w1)
> >>
> >>
> >> I'm very new to matlab, and teaching myself. I've tried several codes
> >> involving 'color' but do not know how to write it properly, any help
> >> would be appreciated.
> >
> > figure(2)
> > hold on
> > plot(x,y1,'b')
> > plot(x,y2,'g')
> > plot(x,y3,'r')
> > etc
> >
> > Hope this helps. Also see
> >
> > help plot
> >
> > doc plot
> ...
>
> And, to make it slightly more general, make up a colors vector of the
> entries in the predefined list
>
> colors={'b';'g';'r'; ... }; % fill in rest of list in lieu of ...
> plot(x,y(i),colors{i}) % i is a variable index in your loop, say
>
> NB since colors is cell array, use the {} to dereference it. Or, it
> could be a character array since is one character, but if then wanted to
> add a line character to be more than a single character have to address
> it as the 2D array instead of the single cell index.
>
> Thank you so much.

Tags for this Thread

No tags are associated with this thread.

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.

Contact us