bugGNU Octave - Bugs: bug #65661, bar plot unable to set individual...


bug #65661: bar plot unable to set individual bar colors

Submitter:  Nicholas Jankowski <nrjank>
Submitted:  Mon 29 Apr 2024 09:15:13 PM UTC
Category:  Plotting Severity:  1 - Wish
Priority:  3 - Low Item Group:  Feature Request
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup

Mon 29 Apr 2024 09:16:01 PM UTC, comment #1: 

as an example, the following patch vs default would somewhat enable this capability, although not perfectly:

--- a/scripts/plot/draw/private/__bar__.m       Mon Apr 29 16:25:41 2024 -0400
+++ b/scripts/plot/draw/private/__bar__.m       Mon Apr 29 17:08:35 2024 -0400
@@ -360,11 +360,15 @@
     addproperty ("facecolor", hg, "patchfacecolor", get (h, "facecolor"));
     addproperty ("linestyle", hg, "patchlinestyle", get (h, "linestyle"));
     addproperty ("linewidth", hg, "patchlinewidth", get (h, "linewidth"));
+    addproperty ("cdata", hg, "patchcdata", get (h, "cdata"));
+    addproperty ("facevertexcdata", hg, "patchfacevertexcdata", get (h, "facevertexcdata"));

     addlistener (hg, "edgecolor", @update_props);
     addlistener (hg, "facecolor", @update_props);
     addlistener (hg, "linestyle", @update_props);
     addlistener (hg, "linewidth", @update_props);
+    addlistener (hg, "cdata", @update_props);
+    addlistener (hg, "facevertexcdata", @update_props);

     if (isvector (x))
       addproperty ("xdata", hg, "data", x);
@@ -495,8 +499,8 @@

 function update_props (h, ~)
   kids = get (h, "children");
-  set (kids, {"edgecolor", "linewidth", "linestyle", "facecolor"},
-       get (h, {"edgecolor", "linewidth", "linestyle", "facecolor"}));
+  set (kids, {"edgecolor", "linewidth", "linestyle", "facecolor", "cdata", "facevertexcdata"},
+       get (h, {"edgecolor", "linewidth", "linestyle", "facecolor", "cdata", "facevertexcdata"}));

 function update_data (h, ~)

with that change, the following commands will change face colors in a couple different ways:

h = bar ([1, 2, 3, 4, 5]);
set (h, 'facevertexcdata', [0 0 0]);
set (h, 'facecolor', 'flat');
set (h, 'facevertexcdata', [0 0 0; 1 0 0; 0 1 0; 0 0 1; 1 1 1]);
set (h, 'facecolor', 'r');
set (h, 'facecolor', 'flat');

i'm not exactly sure why i need to cycle it from 'flat' to something else and back for it to recognize the facevertexcdata change. also i'm not sure why it's not looking at cdata, since the patch was defined with (x,y, 'cdata') in `__bar__`, but it shows the idea.

Nicholas Jankowski <nrjank>
Group Member
Mon 29 Apr 2024 09:15:13 PM UTC, original submission:  

as briefly discussed over in bug #65315, because octave creates a custom bar hggroup for bar graphs, it cannot accept all of the options available in Matlab's bar object, which appears to be a subclass of patch objects.  just like with patch objects, you can specify colors by defining something like

h.facecolor = "flat"
h.CData = [r g b]

or similar specifying colors for each face or vertex.

hggroup / bargroup objects in octave do not have the full set of patch properties available, likely because that was not a compatibility requirement when old bar graph objects were first created.  As it is likely to be some time before octave implements fully compatible, object oriented graphics objects, i'm creating this wish list item to capture the idea of pulling additional properties, such as for color, into the bargroup definition.

Nicholas Jankowski <nrjank>
Group Member


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by nrjank (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.


    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-04-29 nrjank Priority5 - Normal 3 - Low

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code