[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
axes color order ?
From: |
John W. Eaton |
Subject: |
axes color order ? |
Date: |
Fri, 05 Oct 2007 16:52:07 -0400 |
On 5-Oct-2007, Schirmacher, Rolf wrote:
| I want to define a certain color order for the lines coming up in a plot,
| i.e. some special colors instead of the standard of blue, green, red, ...
|
| In octave 2.9.13, the colors are defined by the color_rotation array in the
| __next_line_color__.m function of the plot package. Whenever a new axes is
| created, the color_index is reset and the persistent variable color_rotation
| is refreshed with the fixed default values. So it seems like supplying
| different values in this function should do what I want... color handling
| like choosing the next and using it for the plot is completely implemented
| ... fine!
|
| Now, at the other program, there seems to be a "ColorOrder" property of an
| axes and this defines the array of rgb values in the way as it could
| directly be used in __next_line_color__.m instead of the default
| color_rotation there. In addition, a figure has a "DefaultAxesColorOrder"
| property which is inherited by default by all axes within the figure and the
| root figure (handle 0) also has such a property which is by default
| inherited by all figures, so setting the "DefaultAxesColorOrder" for handle
| 0 makes all figures appear with the customised color orders.
|
| These properties are currently not implemented in octave.
|
| My question is: Is there any simple, "user space" (i.e. m-files only) way to
| add an additional property to a graphics object? Then I could easily add the
| properties and their handling to the existing code. Actually I did not find
| such a possibility nor did I find any hint in the documentation (get/set
| seem to work for predefined properties only...)
No, currently properties can only be added in the C++ classes that
implement the graphics properties in Octave. It is not terribly
difficult to do this. How about the following patch? Does it do what
you need? If not, then I encourage you to submit a patch that makes
this new property behave correctly.
Thanks,
jwe
scripts/ChangeLog:
2007-10-05 John W. Eaton <address@hidden>
* plot/__next_line_color__.m: Get color_rotation from axes
colororder property.
src/ChangeLog:
2007-10-05 John W. Eaton <address@hidden>
* graphics.h.in (axes::properties): New property, colororder.
* graphics.cc (default_colororder): New function.
(axes::properties::properties, axes::properties::get,
axes::properties::set_defaults,
axes::properties::factory_defaults, ): Handle colororder.
Index: scripts/plot/__next_line_color__.m
===================================================================
RCS file: /cvs/octave/scripts/plot/__next_line_color__.m,v
retrieving revision 1.3
diff -u -u -r1.3 __next_line_color__.m
--- scripts/plot/__next_line_color__.m 13 Sep 2007 18:22:38 -0000 1.3
+++ scripts/plot/__next_line_color__.m 5 Oct 2007 20:48:51 -0000
@@ -25,25 +25,22 @@
function rgb = __next_line_color__ (reset)
- persistent color_rotation = [ 0, 0, 1;
- 0, 0.5, 0;
- 1, 0, 0;
- 0, 0.75, 0.75;
- 0.75, 0, 0.75;
- 0.75, 0.75, 0;
- 0.25, 0.25, 0.25];
-
- persistent num_colors = rows (color_rotation);
- persistent color_index = 1;
+ 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);
color_index = 1;
- else
+ elseif (! isempty (color_rotation))
rgb = color_rotation(color_index,:);
if (++color_index > num_colors)
color_index = 1;
endif
+ else
+ error ("__next_line_color__: color_rotation not initialized");
endif
else
print_usage ();
Index: src/graphics.cc
===================================================================
RCS file: /cvs/octave/src/graphics.cc,v
retrieving revision 1.37
diff -u -u -r1.37 graphics.cc
--- src/graphics.cc 2 Oct 2007 20:47:22 -0000 1.37
+++ src/graphics.cc 5 Oct 2007 20:48:55 -0000
@@ -1001,6 +1001,33 @@
// ---------------------------------------------------------------------
+static Matrix
+default_colororder (void)
+{
+ Matrix retval (7, 3, 0.0);
+
+ retval(0,2) = 1.0;
+
+ retval(1,1) = 0.5;
+
+ retval(2,0) = 1.0;
+
+ retval(3,1) = 0.75;
+ retval(3,2) = 0.75;
+
+ retval(4,0) = 0.75;
+ retval(4,2) = 0.75;
+
+ retval(5,0) = 0.75;
+ retval(5,1) = 0.75;
+
+ retval(6,0) = 0.25;
+ retval(6,1) = 0.25;
+ retval(6,2) = 0.25;
+
+ return retval;
+}
+
axes::properties::properties (const graphics_handle& mh,
const graphics_handle& p)
: base_properties (go_name, mh, p),
@@ -1010,6 +1037,7 @@
key ("off"),
keybox ("off"),
keypos (1),
+ colororder (default_colororder ()),
dataaspectratio (Matrix (1, 3, 1.0)),
dataaspectratiomode ("auto"),
xlim (),
@@ -1163,6 +1191,8 @@
set_keybox (val);
else if (name.compare ("keypos"))
set_keypos (val);
+ else if (name.compare ("colororder"))
+ set_colororder (val);
else if (name.compare ("dataaspectratio"))
set_dataaspectratio (val);
else if (name.compare ("dataaspectratiomode"))
@@ -1269,6 +1299,7 @@
key = "off";
keybox = "off";
keypos = 1;
+ colororder = default_colororder ();
dataaspectratio = Matrix (1, 3, 1.0);
dataaspectratiomode = "auto";
@@ -1392,6 +1423,7 @@
m.assign ("key", key);
m.assign ("keybox", keybox);
m.assign ("keypos", keypos);
+ m.assign ("colororder", colororder);
m.assign ("dataaspectratio", dataaspectratio);
m.assign ("dataaspectratiomode", dataaspectratiomode);
m.assign ("xlim", xlim);
@@ -1464,6 +1496,8 @@
retval = keybox;
else if (name.compare ("keypos"))
retval = keypos;
+ else if (name.compare ("colororder"))
+ retval = colororder;
else if (name.compare ("dataaspectratio"))
retval = dataaspectratio;
else if (name.compare ("dataaspectratiomode"))
@@ -1593,6 +1627,7 @@
m["key"] = "off";
m["keybox"] = "off";
m["keypos"] = 1;
+ m["colororder"] = default_colororder ();
m["dataaspectratio"] = Matrix (1, 3, 1.0);
m["dataaspectratiomode"] = "auto";
Index: src/graphics.h.in
===================================================================
RCS file: /cvs/octave/src/graphics.h.in,v
retrieving revision 1.7
diff -u -u -r1.7 graphics.h.in
--- src/graphics.h.in 1 Oct 2007 15:59:33 -0000 1.7
+++ src/graphics.h.in 5 Oct 2007 20:48:55 -0000
@@ -1136,6 +1136,7 @@
octave_value key
octave_value keybox
octave_value keypos
+ octave_value colororder
octave_value dataaspectratio m
octave_value dataaspectratiomode
octave_value xlim m