

Hi,
I've compiled the latest Octave (3.0.2) And the latest released gnuplot (4.2.3).
I'm vexed by octave/gnuplot not changing colors when plotting additional plots with holdon. Yes, I know I can set colors manually (or pass all arguments to one big plot call)  but this is:
1) Cumbersome for normal plots.
2) Even more cumbersome when using hist() and other builtin functions ontop of plot (with hist, you can get the output, and then call yet another function (bar  that doesn't produce exactly the same results ([x,y] = hist(z); bar(y,x);  is visually different than hist(z)  probably some style default?)....).
This used to work properly in previous (<2.9.x) versions of octave. I use plots extensively, typically, I'll crunch some numbers in the command line and blurt them out as a plot/histogram (much easier to do this in octave than in gnuplot, any manipulation/processing/filtering is so much easier inside of octave). Just about every second plot I make involves multiple
Is there any quick solution for this?
Is this a gnuplot issue (e.g. like the zoom problem)? Will this be solved if I compile the unstable gnuplot 4.3?
Is there any way I can patch octave to fix this (e.g., changing the default 'blue' to something cyclic, and intercepting hold and resetting said cyclic variable?)?
Man thanks,
Ben Boxman

Administrator

On Sep 1, 2008, at 5:25 PM, Ben Boxman wrote: Hi,
I've compiled the latest Octave (3.0.2) And the latest released gnuplot (4.2.3).
I'm vexed by octave/gnuplot not changing colors when plotting additional plots with holdon. Yes, I know I can set colors manually (or pass all arguments to one big plot call)  but this is: 1) Cumbersome for normal plots. 2) Even more cumbersome when using hist() and other builtin functions ontop of plot (with hist, you can get the output, and then call yet another function (bar  that doesn't produce exactly the same results ([x,y] = hist(z); bar(y,x);  is visually different than hist(z)  probably some style default?)....).
This used to work properly in previous (<2.9.x) versions of octave. I use plots extensively, typically, I'll crunch some numbers in the command line and blurt them out as a plot/histogram (much easier to do this in octave than in gnuplot, any manipulation/processing/filtering is so much easier inside of octave). Just about every second plot I make involves multiple
Is there any quick solution for this?
Is this a gnuplot issue (e.g. like the zoom problem)? Will this be solved if I compile the unstable gnuplot 4.3? Is there any way I can patch octave to fix this (e.g., changing the default 'blue' to something cyclic, and intercepting hold and resetting said cyclic variable?)?
Man thanks,
Ben Boxman
The Octave developers are actively working to improve Octave's compatibility with Matlab.
Regarding the order of the colors, you can change the order by modifying the "colororder" property associated with the axis. See ...
> get (gca, 'colororder')
ans =
0.00000 0.00000 1.00000 0.00000 0.50000 0.00000 1.00000 0.00000 0.00000 0.00000 0.75000 0.75000 0.75000 0.00000 0.75000 0.75000 0.75000 0.00000 0.25000 0.25000 0.25000
so you could
colors = get (gca, 'colororder')
them modify the colors and/or order and then
set (gca, 'colororder', colors)
Is that sufficient for you needs?
Ben
_______________________________________________
Helpoctave mailing list
[hidden email]
https://wwwold.cae.wisc.edu/mailman/listinfo/helpoctave


On Mon, 20080901 at 21:00 0500, [hidden email] wrote:
> Message: 6
> Date: Mon, 01 Sep 2008 18:39:12 0400
> From: Ben Abbott < [hidden email]>
> Subject: Re: Plotting, holdon, colors
> To: Ben Boxman < [hidden email]>
> Cc: [hidden email]
> MessageID: < [hidden email]>
> ContentType: text/plain; charset="usascii"
>
>
> On Sep 1, 2008, at 5:25 PM, Ben Boxman wrote:
>
> >
> > Hi,
> >
> > I've compiled the latest Octave (3.0.2) And the latest released
> > gnuplot
> > (4.2.3).
> >
> > I'm vexed by octave/gnuplot not changing colors when plotting
> > additional
> > plots with holdon. Yes, I know I can set colors manually (or pass
> all
> > arguments to one big plot call)  but this is:
> > 1) Cumbersome for normal plots.
> > 2) Even more cumbersome when using hist() and other builtin
> functions
> > ontop of plot (with hist, you can get the output, and then call
> yet
> > another
> > function (bar  that doesn't produce exactly the same results
> > ([x,y] =
> > hist(z); bar(y,x);  is visually different than hist(z) 
> > probably some
> > style default?)....).
> >
> > This used to work properly in previous (<2.9.x) versions of
> octave.
> > I use
> > plots extensively, typically, I'll crunch some numbers in the
> > command line
> > and blurt them out as a plot/histogram (much easier to do this in
> > octave
> > than in gnuplot, any manipulation/processing/filtering is so much
> > easier
> > inside of octave). Just about every second plot I make involves
> > multiple
> >
> > Is there any quick solution for this?
> >
> > Is this a gnuplot issue (e.g. like the zoom problem)? Will this
> be
> > solved
> > if I compile the unstable gnuplot 4.3?
> > Is there any way I can patch octave to fix this (e.g., changing the
> > default 'blue' to something cyclic, and intercepting hold and
> > resetting said
> > cyclic variable?)?
> >
> >
> > Man thanks,
> >
> > Ben Boxman
>
> The Octave developers are actively working to improve Octave's
> compatibility with Matlab.
>
> Regarding the order of the colors, you can change the order by
> modifying the "colororder" property associated with the axis. See ...
>
> > get (gca, 'colororder')
>
> ans = 0.00000 0.00000 1.00000
> 0.00000 0.50000 0.00000
> 1.00000 0.00000 0.00000
> 0.00000 0.75000 0.75000
> 0.75000 0.00000 0.75000
> 0.75000 0.75000 0.00000
> 0.25000 0.25000 0.25000
>
> so you could
>
> colors = get (gca, 'colororder')
>
> them modify the colors and/or order and then
>
> set (gca, 'colororder', colors)
>
> Is that sufficient for you needs?
>
> Ben
As far as I can tell, the above solution works with plots where all
lines (=data sets) are plotted using one single plot command.
However, the original question was related to the situation, where one
plots the first data set using plot(...), then 'hold on', and the plot
another data set above the first using a second plot(...). I believe to
remember that Matlab does indeed use a different color for the second
plot (but it's a long time since I used Matlab), so I'd suggest to
change this behaviour in some future version of Octave. In the meantime,
I'd suggest to write a custom function that handles the plot color and
the 'hold on', e.g. somthing like this (not tested):
function h = my_plot (x,y)
global my_col
if ~exist('my_col')
my_col = 0;
end
my_col = my_col+1;
c = get (gca,'colororder); c = c(my_col,:);
plot (x,y,c)
endfunction
_______________________________________________
Helpoctave mailing list
[hidden email]
https://wwwold.cae.wisc.edu/mailman/listinfo/helpoctave


Hi,
I tried "set (gca, 'colororder', colors)", but what this seems to allow me is to change the order of the colors as used by plot (e.g. changing the second used color from green to red). This is isn't my problem  I'm having a problem with "hold on".
My problem is not the actual colors in the color order, but that toggling "hold on" will keep the same color. For instance, if I do the following:
x = [1:100]
plot(x, sin(x), x, cos(y))
I get a graph with sin(x) showing up with one color, and cos(y) showing up with another (for some reason, blue and green).
However, if I do:
hold off;
plot(x, sin(x))
hold on;
plot(x, sin(y))
I get a graph with sin(x) and cos(x) sharing the same color (blue).
This used to work properly in the old octave chain (i.e. 2.1.x) and seems to be broken at least from 2.9.x.
I want to use hold. It is inconvenient to:
1) Set colors manually for each plot.
or:
2) Pass these all off as one plot.
And  if I'm using another function that produces a plot (e.g. hist, or pwelch, or perhaps even one of my own)  which I wish to superimpose on another, it can get even more difficult.
Many thanks,
Ben Boxman
Ben Abbott wrote
On Sep 1, 2008, at 5:25 PM, Ben Boxman wrote:
>
> Hi,
>
> I've compiled the latest Octave (3.0.2) And the latest released
> gnuplot
> (4.2.3).
>
> I'm vexed by octave/gnuplot not changing colors when plotting
> additional
> plots with holdon. Yes, I know I can set colors manually (or pass all
> arguments to one big plot call)  but this is:
> 1) Cumbersome for normal plots.
> 2) Even more cumbersome when using hist() and other builtin functions
> ontop of plot (with hist, you can get the output, and then call yet
> another
> function (bar  that doesn't produce exactly the same results
> ([x,y] =
> hist(z); bar(y,x);  is visually different than hist(z) 
> probably some
> style default?)....).
>
> This used to work properly in previous (<2.9.x) versions of octave.
> I use
> plots extensively, typically, I'll crunch some numbers in the
> command line
> and blurt them out as a plot/histogram (much easier to do this in
> octave
> than in gnuplot, any manipulation/processing/filtering is so much
> easier
> inside of octave). Just about every second plot I make involves
> multiple
>
> Is there any quick solution for this?
>
> Is this a gnuplot issue (e.g. like the zoom problem)? Will this be
> solved
> if I compile the unstable gnuplot 4.3?
> Is there any way I can patch octave to fix this (e.g., changing the
> default 'blue' to something cyclic, and intercepting hold and
> resetting said
> cyclic variable?)?
>
>
> Man thanks,
>
> Ben Boxman
The Octave developers are actively working to improve Octave's
compatibility with Matlab.
Regarding the order of the colors, you can change the order by
modifying the "colororder" property associated with the axis. See ...
> get (gca, 'colororder')
ans = 0.00000 0.00000 1.00000
0.00000 0.50000 0.00000
1.00000 0.00000 0.00000
0.00000 0.75000 0.75000
0.75000 0.00000 0.75000
0.75000 0.75000 0.00000
0.25000 0.25000 0.25000
so you could
colors = get (gca, 'colororder')
them modify the colors and/or order and then
set (gca, 'colororder', colors)
Is that sufficient for you needs?
Ben
_______________________________________________
Helpoctave mailing list
Helpoctave@octave.org
https://wwwold.cae.wisc.edu/mailman/listinfo/helpoctave


In reply to this post by Matthias Brennwald (bwm)
On Tue, Sep 2, 2008 at 8:31 AM, Matthias Brennwald
< [hidden email]> wrote:
> As far as I can tell, the above solution works with plots where all
> lines (=data sets) are plotted using one single plot command.
>
> However, the original question was related to the situation, where one
> plots the first data set using plot(...), then 'hold on', and the plot
> another data set above the first using a second plot(...). I believe to
> remember that Matlab does indeed use a different color for the second
> plot (but it's a long time since I used Matlab),
No, it does not (Matlab 2006b).
Michael.
_______________________________________________
Helpoctave mailing list
[hidden email]
https://wwwold.cae.wisc.edu/mailman/listinfo/helpoctave


In reply to this post by Matthias Brennwald (bwm)
Hi,
If I do this, is there any way I can "overload" the plot() function such that any call to plot(x) or plot(x,y) (one or two argument plots) will go to my_plot() instead of plot()?
Or would this require a hack in the code? (pointers as to which files/modules should be changed would be much appreciated).
Ben
Matthias Brennwald (bwm) wrote
On Mon, 20080901 at 21:00 0500, helpoctaverequest@octave.org wrote:
> Message: 6
> Date: Mon, 01 Sep 2008 18:39:12 0400
> From: Ben Abbott <bpabbott@mac.com> > Subject: Re: Plotting, holdon, colors
> To: Ben Boxman <bboxman@walla.com> > Cc: helpoctave@octave.org
> MessageID: <FE85B1CB788E40F2A0BF873BE2EF2482@mac.com> > ContentType: text/plain; charset="usascii"
>
>
> On Sep 1, 2008, at 5:25 PM, Ben Boxman wrote:
>
> >
> > Hi,
> >
> > I've compiled the latest Octave (3.0.2) And the latest released
> > gnuplot
> > (4.2.3).
> >
> > I'm vexed by octave/gnuplot not changing colors when plotting
> > additional
> > plots with holdon. Yes, I know I can set colors manually (or pass
> all
> > arguments to one big plot call)  but this is:
> > 1) Cumbersome for normal plots.
> > 2) Even more cumbersome when using hist() and other builtin
> functions
> > ontop of plot (with hist, you can get the output, and then call
> yet
> > another
> > function (bar  that doesn't produce exactly the same results
> > ([x,y] =
> > hist(z); bar(y,x);  is visually different than hist(z) 
> > probably some
> > style default?)....).
> >
> > This used to work properly in previous (<2.9.x) versions of
> octave.
> > I use
> > plots extensively, typically, I'll crunch some numbers in the
> > command line
> > and blurt them out as a plot/histogram (much easier to do this in
> > octave
> > than in gnuplot, any manipulation/processing/filtering is so much
> > easier
> > inside of octave). Just about every second plot I make involves
> > multiple
> >
> > Is there any quick solution for this?
> >
> > Is this a gnuplot issue (e.g. like the zoom problem)? Will this
> be
> > solved
> > if I compile the unstable gnuplot 4.3?
> > Is there any way I can patch octave to fix this (e.g., changing the
> > default 'blue' to something cyclic, and intercepting hold and
> > resetting said
> > cyclic variable?)?
> >
> >
> > Man thanks,
> >
> > Ben Boxman
>
> The Octave developers are actively working to improve Octave's
> compatibility with Matlab.
>
> Regarding the order of the colors, you can change the order by
> modifying the "colororder" property associated with the axis. See ...
>
> > get (gca, 'colororder')
>
> ans = 0.00000 0.00000 1.00000
> 0.00000 0.50000 0.00000
> 1.00000 0.00000 0.00000
> 0.00000 0.75000 0.75000
> 0.75000 0.00000 0.75000
> 0.75000 0.75000 0.00000
> 0.25000 0.25000 0.25000
>
> so you could
>
> colors = get (gca, 'colororder')
>
> them modify the colors and/or order and then
>
> set (gca, 'colororder', colors)
>
> Is that sufficient for you needs?
>
> Ben
As far as I can tell, the above solution works with plots where all
lines (=data sets) are plotted using one single plot command.
However, the original question was related to the situation, where one
plots the first data set using plot(...), then 'hold on', and the plot
another data set above the first using a second plot(...). I believe to
remember that Matlab does indeed use a different color for the second
plot (but it's a long time since I used Matlab), so I'd suggest to
change this behaviour in some future version of Octave. In the meantime,
I'd suggest to write a custom function that handles the plot color and
the 'hold on', e.g. somthing like this (not tested):
function h = my_plot (x,y)
global my_col
if ~exist('my_col')
my_col = 0;
end
my_col = my_col+1;
c = get (gca,'colororder); c = c(my_col,:);
plot (x,y,c)
endfunction
_______________________________________________
Helpoctave mailing list
Helpoctave@octave.org
https://wwwold.cae.wisc.edu/mailman/listinfo/helpoctave

Administrator

On Sep 2, 2008, at 2:54 AM, Ben Boxman wrote:
>
> Hi,
>
> I tried "set (gca, 'colororder', colors)", but what this seems to
> allow me
> is to change the order of the colors as used by plot (e.g. changing
> the
> second used color from green to red). This is isn't my problem 
> I'm having
> a problem with "hold on".
>
> My problem is not the actual colors in the color order, but that
> toggling
> "hold on" will keep the same color. For instance, if I do the
> following:
> x = [1:100]
> plot(x, sin(x), x, cos(y))
> I get a graph with sin(x) showing up with one color, and cos(y)
> showing up
> with another (for some reason, blue and green).
>
> However, if I do:
> hold off;
> plot(x, sin(x))
> hold on;
> plot(x, sin(y))
> I get a graph with sin(x) and cos(x) sharing the same color (blue).
>
> This used to work properly in the old octave chain (i.e. 2.1.x) and
> seems to
> be broken at least from 2.9.x.
>
> I want to use hold. It is inconvenient to:
> 1) Set colors manually for each plot.
> or:
> 2) Pass these all off as one plot.
> And  if I'm using another function that produces a plot (e.g.
> hist, or
> pwelch, or perhaps even one of my own)  which I wish to
> superimpose on
> another, it can get even more difficult.
>
>
> Many thanks,
>
> Ben Boxman
is the following to much trouble?
hold off
plot (x, sin(x), 'b')
hold on
plot (x, cos(x), 'r')
Ben
_______________________________________________
Helpoctave mailing list
[hidden email]
https://wwwold.cae.wisc.edu/mailman/listinfo/helpoctave


Setting colors manually works if you are dealing with a "simple" plot (though this is somewhat annoying). This becomes a bit more "icky" if you're using other functions that end up calling plot (for instance: hist, pwelch, or a user function)  there is a workaround (in that you can receive the raw plot data, and then call plot (or bar), rewrite said user function to set a color externally (in lieu of the default color)), but this requires multiple steps + setting colors for each and every one.
(e.g. two hists() with hold on also aren't satisfactory)
My primary reason for using octave is convenience  I can both process & visualize my data (which is often produced by a nonoctave environment)  and I can do both in a simple/efficient manner  which I can't do, as easily, outside of octave.
Ben
Ben Abbott wrote
On Sep 2, 2008, at 2:54 AM, Ben Boxman wrote:
>
> Hi,
>
> I tried "set (gca, 'colororder', colors)", but what this seems to
> allow me
> is to change the order of the colors as used by plot (e.g. changing
> the
> second used color from green to red). This is isn't my problem 
> I'm having
> a problem with "hold on".
>
> My problem is not the actual colors in the color order, but that
> toggling
> "hold on" will keep the same color. For instance, if I do the
> following:
> x = [1:100]
> plot(x, sin(x), x, cos(y))
> I get a graph with sin(x) showing up with one color, and cos(y)
> showing up
> with another (for some reason, blue and green).
>
> However, if I do:
> hold off;
> plot(x, sin(x))
> hold on;
> plot(x, sin(y))
> I get a graph with sin(x) and cos(x) sharing the same color (blue).
>
> This used to work properly in the old octave chain (i.e. 2.1.x) and
> seems to
> be broken at least from 2.9.x.
>
> I want to use hold. It is inconvenient to:
> 1) Set colors manually for each plot.
> or:
> 2) Pass these all off as one plot.
> And  if I'm using another function that produces a plot (e.g.
> hist, or
> pwelch, or perhaps even one of my own)  which I wish to
> superimpose on
> another, it can get even more difficult.
>
>
> Many thanks,
>
> Ben Boxman
is the following to much trouble?
hold off
plot (x, sin(x), 'b')
hold on
plot (x, cos(x), 'r')
Ben
_______________________________________________
Helpoctave mailing list
Helpoctave@octave.org
https://wwwold.cae.wisc.edu/mailman/listinfo/helpoctave


Ben Boxman wrote:
> Setting colors manually works if you are dealing with a "simple" plot
> (though this is somewhat annoying). This becomes a bit more "icky" if you're
> using other functions that end up calling plot (for instance: hist, pwelch,
> or a user function)  there is a workaround (in that you can receive the
> raw plot data, and then call plot (or bar), rewrite said user function to
> set a color externally (in lieu of the default color)), but this requires
> multiple steps + setting colors for each and every one.
> (e.g. two hists() with hold on also aren't satisfactory)
>
> My primary reason for using octave is convenience  I can both process &
> visualize my data (which is often produced by a nonoctave environment) 
> and I can do both in a simple/efficient manner  which I can't do, as
> easily, outside of octave.
>
> Ben
>
The behavior you describe is the Matlab compatible behavior, and many
users seem to want strict compatibility. That being said I can think of
an easy way to get the behavior you want. Try overloading the
__next_line_color__ function. For example add the function
function rgb = __next_line_color__ (reset)
persistent color_rotation = [];
persistent num_colors = [];
persistent color_index = [];
if (nargin < 2)
if (nargin == 1 && reset)
color_rotation = get (gca (), "colororder");
num_colors = rows (color_rotation);
## Don't reset the color_index except if this is first call
if (isempty (color_index)  color_index > num_colors)
color_index = 1;
endif
else
## Need this as original __next_line_color__ called first
if (! isempty (color_rotation))
color_rotation = get (gca (), "colororder");
num_colors = rows (color_rotation);
endif
if (isempty (color_index))
color_index = 1;
endif
rgb = color_rotation(color_index,:);
if (++color_index > num_colors)
color_index = 1;
endif
color_index
rgb
endif
else
print_usage ();
endif
endfunction
in the front of your path. The color_index variable is never reset in
the above and so you'll cycle through the plot colors even if
__next_line_color__(true) is called to reset it.
D.

David Bateman [hidden email]
Motorola Labs  Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob)
91193 GifSurYvette FRANCE +33 1 69 35 77 01 (Fax)
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary
_______________________________________________
Helpoctave mailing list
[hidden email]
https://wwwold.cae.wisc.edu/mailman/listinfo/helpoctave


Many thanks, this worked like a charm  I might do some more poking around in the plot scripts now that I know where they are, :).
I like Octave's nonmatlab compatible features. Octave being more forgiving to "C" style syntax (e.g. " vs. ') is a boon to my ingrained "C" ways. And some octave packages are superior, in functionality, to the Matlab packages.
Ben
David Bateman wrote
Ben Boxman wrote:
> Setting colors manually works if you are dealing with a "simple" plot
> (though this is somewhat annoying). This becomes a bit more "icky" if you're
> using other functions that end up calling plot (for instance: hist, pwelch,
> or a user function)  there is a workaround (in that you can receive the
> raw plot data, and then call plot (or bar), rewrite said user function to
> set a color externally (in lieu of the default color)), but this requires
> multiple steps + setting colors for each and every one.
> (e.g. two hists() with hold on also aren't satisfactory)
>
> My primary reason for using octave is convenience  I can both process &
> visualize my data (which is often produced by a nonoctave environment) 
> and I can do both in a simple/efficient manner  which I can't do, as
> easily, outside of octave.
>
> Ben
>
The behavior you describe is the Matlab compatible behavior, and many
users seem to want strict compatibility. That being said I can think of
an easy way to get the behavior you want. Try overloading the
__next_line_color__ function. For example add the function
function rgb = __next_line_color__ (reset)
persistent color_rotation = [];
persistent num_colors = [];
persistent color_index = [];
if (nargin < 2)
if (nargin == 1 && reset)
color_rotation = get (gca (), "colororder");
num_colors = rows (color_rotation);
## Don't reset the color_index except if this is first call
if (isempty (color_index)  color_index > num_colors)
color_index = 1;
endif
else
## Need this as original __next_line_color__ called first
if (! isempty (color_rotation))
color_rotation = get (gca (), "colororder");
num_colors = rows (color_rotation);
endif
if (isempty (color_index))
color_index = 1;
endif
rgb = color_rotation(color_index,:);
if (++color_index > num_colors)
color_index = 1;
endif
color_index
rgb
endif
else
print_usage ();
endif
endfunction
in the front of your path. The color_index variable is never reset in
the above and so you'll cycle through the plot colors even if
__next_line_color__(true) is called to reset it.
D.

David Bateman David.Bateman@motorola.com
Motorola Labs  Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob)
91193 GifSurYvette FRANCE +33 1 69 35 77 01 (Fax)
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary
_______________________________________________
Helpoctave mailing list
Helpoctave@octave.org
https://wwwold.cae.wisc.edu/mailman/listinfo/helpoctave

