different colours for different curves in the same plot

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

different colours for different curves in the same plot

Federica
Hi,

I'm trying to represent several curves on the same plot using Octave 3.2.4 on Windows. The commands I used to have the unique plot and a relative legend are:

hold on;
   s=sprintf(";Lu= %d;",LU);
plot(t,m,s);

hold off

where m is the result of a differential equation systems. So I have different curves for different m but using these commands I have only a colour for all the curves. Also if I specify the color I have only the specific color I chose and I have it for all the curves. How can I tell to Octave to pick a different color for each curve?

Thank you so much!!!!

Federica
Reply | Threaded
Open this post in threaded view
|

RE: different colours for different curves in the same plot

William Krekeler
Federica

In reference to http://octave.1599824.n4.nabble.com/different-colours-for-different-curves-in-the-same-plot-tp3563544p3563544.html

You need to set the color property of each line. If you only have a few lines to plot then you can do the following.

% start pseudo-code

plotColor = 'brgkmcyw';
figure
for m = 1:length( ydata_sets )
   plot( xdata, ydata(m), sprintf( '%s', plotColor(m) ) )
end

% end pseudo-code

Or if you have a lot of data sets

% start pseudo-code
plotColors = colormap;
figure
for m = 1:length( ydata_sets )
   plotColorsI = round( size( plotColors, 1)* m / length(ydata_sets) );
   hold on  
   H1 = plot( xdata, ydata(m) )
   hold off
   set( H1,'Color', plotColors( plotColorsI,:) );
end
% end pseudo-code

Bill Krekeler
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

RE: different colours for different curves in the same plot

Federica
Thank you William!!!

So if I understand well, I need to define the color property for each line.

I followed your suggestion but I had no results.... an empty plot and all the m values displayed.

The command

for m=1:length(ydata_sets)

refers to the range of values for m, is it right?

m values are between 0 and 1 so it becomes:

% start pseudo-code
plotColors = colormap;
figure
for m = 1:length(1)
   plotColorsI = round( size( plotColors, 1)* m / length(1) );
   hold on  
   plot(t,m);
   H1 = plot(t, m)
   hold off
   set( H1,'Color', plotColors( plotColorsI,:) );
end
% end pseudo-code

And the result is an empty plot!!! What I did wrong??

maybe I need to define the number of lines?

Thank you again,

Federica

Reply | Threaded
Open this post in threaded view
|

RE: different colours for different curves in the same plot

William Krekeler
-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Federica
Sent: Tuesday, May 31, 2011 11:45 AM
To: [hidden email]
Subject: RE: different colours for different curves in the same plot

Thank you William!!!

So if I understand well, I need to define the color property for each line.

I followed your suggestion but I had no results.... an empty plot and all
the m values displayed.

The command

for m=1:length(ydata_sets)

refers to the range of values for m, is it right?

m values are between 0 and 1 so it becomes:

% start pseudo-code
plotColors = colormap;
figure
for m = 1:length(1)
   plotColorsI = round( size( plotColors, 1)* m / length(1) );
   hold on  
   plot(t,m);
   H1 = plot(t, m)
   hold off
   set( H1,'Color', plotColors( plotColorsI,:) );
end
% end pseudo-code

And the result is an empty plot!!! What I did wrong??

maybe I need to define the number of lines?

Thank you again,

Federica



--
View this message in context: http://octave.1599824.n4.nabble.com/different-colours-for-different-curves-in-the-same-plot-tp3563544p3563643.html
Sent from the Octave - General mailing list archive at Nabble.com.
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave

Federica,

Sorry, I grabbed the wrong variable when I was cutting and pasting. In your code m is a non-integer value. In my psuedo-code m is meant to be an integer value. You can replace the variables in my code with any variable name to reduce confusion. Quick description for what I meant: If the y data is M sets of N values then m will step from 1 to M, and all N values associated with the mth set will be colored by the appropriate color. plotColorsI is just grabbing the integer index into the colormap that is defined by the ratio of mth set over total number of sets. If M is large with respect to the colormap size this will result in overlapping color designations.

Based upon the fact that you replaced the length of the y data columns value with length(1) in both places I think I may have misunderstood what you actually wanted to do.

What does size(m) return in your code before you rewrote my pseudo-code?

I rewrote the pseudo code to explicitly explain what I meant.

% start pseudo-code (that should run) rewritten to explain what I meant
xdata = 1:10;
ydata_sets = rand(4,10); % arbitrary definition
numberDataSets = size( ydata_sets,1 ); % used size instead to be explicit
m = ydata_sets(1,:); % this assumes that m is 1 vector from the parent set of vectors which is what I originally expected based upon your description
plotColors = colormap;
figure;
for nIndex = 1: numberDataSets
   plotColorsI = round( size( plotColors, 1)* nIndex / numberDataSets );
   hold on  
   H1 = plot( xdata, ydata_sets(nIndex,:) );
   hold off
   set( H1,'Color', plotColors( plotColorsI,:) );
end

% end pseudo-code


_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

RE: different colours for different curves in the same plot

Bernard Watts
In reply to this post by Federica
I used this to plot some data for 7 curves on the same plot (with help  
from Ben Abbott). It's not perfect as some line colours can be very  
similar.

species = csvread ("cadmium.csv")
specname = {"lCd"; "lCdOH"; "lCdOH2"; "lCdOH3"; "lCdOH4"; "lCd2OH4";  
"lCd4OH4"};
for i = 2:8
        r=i/10
        g=1-i/10
        b=i/10
        (specname(i-1))
        plot  (species ( :, 1), species( :, i), sprintf (';%s;',  
specname{i-1}), 'Linewidth', 2, 'Color', [r g b])
        hold ("on");
endfor

Bernie
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: different colours for different curves in the same plot

mafaraxas
In reply to this post by Federica


On Tue, May 31, 2011 at 9:59 AM, Federica <[hidden email]> wrote:
Hi,

I'm trying to represent several curves on the same plot using Octave 3.2.4
on Windows. The commands I used to have the unique plot and a relative
legend are:

hold on;
  s=sprintf(";Lu= %d;",LU);
plot(t,m,s);

hold off

where m is the result of a differential equation systems. So I have
different curves for different m but using these commands I have only a
colour for all the curves. Also if I specify the color I have only the
specific color I chose and I have it for all the curves. How can I tell to
Octave to pick a different color for each curve?

Thank you so much!!!!

Federica

I haven't looked very carefully at the previous suggestions, other than that they are all using loops.  I believe that is the best you can do if you want to specify colors.  If you don't care what the colors are for your plots, assuming you have x_data of size 1xN and y_data size MxN, where M is the number of solutions/whatever, you should be able to do

plot(x_data,y_data)

and Octave will automatically plot each solution separately in different colors.  I don't know how many colors it cycles through or the criteria for the colors chosen, but I thought I should point that out.

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: different colours for different curves in the same plot

marco atzeri-2
On Thu, Jun 2, 2011 at 8:15 AM, Moo wrote:

> On Tue, May 31, 2011 at 9:59 AM, Federica
> wrote:
>>
>> Hi,
>>
>> I'm trying to represent several curves on the same plot using Octave 3.2.4
>> on Windows. The commands I used to have the unique plot and a relative
>> legend are:
>>
>> hold on;
>>   s=sprintf(";Lu= %d;",LU);
>> plot(t,m,s);
>>
>> hold off
>>
>> where m is the result of a differential equation systems. So I have
>> different curves for different m but using these commands I have only a
>> colour for all the curves. Also if I specify the color I have only the
>> specific color I chose and I have it for all the curves. How can I tell to
>> Octave to pick a different color for each curve?
>>
>> Thank you so much!!!!
>>
>> Federica
>
> I haven't looked very carefully at the previous suggestions, other than that
> they are all using loops.  I believe that is the best you can do if you want
> to specify colors.  If you don't care what the colors are for your plots,
> assuming you have x_data of size 1xN and y_data size MxN, where M is the
> number of solutions/whatever, you should be able to do
>
> plot(x_data,y_data)
>
> and Octave will automatically plot each solution separately in different
> colors.  I don't know how many colors it cycles through or the criteria for
> the colors chosen, but I thought I should point that out.
>

Hi Moo,
plot chose different colors (up to 6) if you specify all the data in
the same plot command

plot(x1_data,y1_data,x2_data,y2_data,x3_data,y3_data)

but she can not use it as the number of curves is not fixed.

but with

hold on
for i:1:n
  plot(x_data(i),yi_data(j))
endfor
hold off

all the curves have the same color, and this is the problem of Federica

Regards
Marco
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: different colours for different curves in the same plot

marco atzeri-2
On Thu, Jun 2, 2011 at 8:38 AM, marco atzeri  wrote:

> plot chose different colors (up to 6) if you specify all the data in
> the same plot command
>
> plot(x1_data,y1_data,x2_data,y2_data,x3_data,y3_data)
>
> but she can not use it as the number of curves is not fixed.
>
> but with
>
> hold on
> for i:1:n
>  plot(x_data(i),yi_data(j))
> endfor
> hold off
>
> all the curves have the same color, and this is the problem of Federica
>
> Regards
> Marco
>

a simple solution for random color is

hold on
for i=1:n
  plot(x_data(i),yi_data(j),"Color",rand(1,3))
endfor
hold off

so all the curves will have random color specified as RGB triple

Marco
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave