Plotting, hold-on, colors
David Bateman
David.Bateman at motorola.com
Tue Sep 2 08:01:13 CDT 2008
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 work-around (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 non-octave 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 at 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 Gif-Sur-Yvette 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
More information about the Help-octave
mailing list