changeset 29139:f5e89a80ba8c

Use colors from "colormap" property for bar, barh if a "hist" option was given (bug #59589). * NEWS: Announce change * bar.m: Update documentation to point out that colors are taken from "ColorOrder" property for "stacked" or "grouped" option, but from "ColorMap" property for "hist" or "histc" option. This is Matlab compatible, and also possibly dumb. * hist.m: Update documentation to state that "ColorMap" property will be used for color selection. * __bar__.m: Add new variable ishist to indicate that a histogram option was given. Set "climmode" of axis to "auto" so that colormap data is correctly shown. * __bar__.m (bars): When ishist is true, set "cdata" field of patch object to the index of the bar group (1,2,3,...).
author Rik <rik@octave.org>
date Thu, 03 Dec 2020 17:46:40 -0800
parents eacd1a3417c3
children c7498b5aece0
files NEWS scripts/plot/draw/bar.m scripts/plot/draw/hist.m scripts/plot/draw/private/__bar__.m
diffstat 4 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue Dec 01 22:59:35 2020 +0100
+++ b/NEWS	Thu Dec 03 17:46:40 2020 -0800
@@ -164,9 +164,9 @@
 Previously the negative bars could overlap positive bars depending on
 drawing order.
 
-- The functions `bar`, `barh`, and `hist` now use colors from the
-`"ColorOrder"` axes property rather than the `"Colormap"` figure
-property.
+- The functions `bar` and `barh` now use colors from the `"ColorOrder"`
+axes property rather than the `"Colormap"` figure property unless one
+of the histogram options (@qcode{"hist"}, @qcode{"histc"} was specified.
 
 - The function `saveas` now defaults to saving in Octave figure format
 (.ofig) rather than PDF (.pdf).
--- a/scripts/plot/draw/bar.m	Tue Dec 01 22:59:35 2020 +0100
+++ b/scripts/plot/draw/bar.m	Thu Dec 03 17:46:40 2020 -0800
@@ -95,8 +95,10 @@
 ##
 ## @noindent
 ## The default color for bars is taken from the axes' @qcode{"ColorOrder"}
-## property.  The color of bars can also be set manually using the
-## @qcode{"facecolor"} property as shown below.
+## property.  The default color for bars when a histogram option
+## (@qcode{"hist"}, @qcode{"histc"} is used is the @qcode{"Colormap"} property
+## of either the axes or figure.  The color of bars can also be set manually
+## using the @qcode{"facecolor"} property as shown below.
 ##
 ## @example
 ## @group
--- a/scripts/plot/draw/hist.m	Tue Dec 01 22:59:35 2020 +0100
+++ b/scripts/plot/draw/hist.m	Thu Dec 03 17:46:40 2020 -0800
@@ -62,8 +62,8 @@
 ##
 ## @noindent
 ## The full list of patch properties is documented at @ref{Patch Properties}.
-## If not specified, the default colors for the histogram are taken from the
-## axes' @qcode{"ColorOrder"} property.
+## property.  If not specified, the default colors for the histogram are taken
+## from the @qcode{"Colormap"} property of the axes or figure.
 ##
 ## If the first argument @var{hax} is an axes handle, then plot into this axes,
 ## rather than the current axes returned by @code{gca}.
--- a/scripts/plot/draw/private/__bar__.m	Tue Dec 01 22:59:35 2020 +0100
+++ b/scripts/plot/draw/private/__bar__.m	Thu Dec 03 17:46:40 2020 -0800
@@ -125,6 +125,8 @@
     endif
   endwhile
 
+  ishist = islogical (histc);
+
   ngrp = rows (x);
 
   if (isvector (y) && ngrp != rows (y))
@@ -137,7 +139,7 @@
   nbars = columns (y);
 
   ## Column width is 1 for 'hist*' styles (bars touch).
-  if (islogical (histc))
+  if (ishist)
     cwidth = 1;
     if (nbars == 1)
       gwidth = 1;
@@ -173,7 +175,7 @@
   xb = repmat ([x1; x1; x2; x2](:), 1, nbars);
 
   if (group)
-    if (islogical (histc) && histc)
+    if (ishist && histc)
       offset = 2*cdelta * [0:(nbars-1)] + cdelta(1);  # not centered
     else
       offset = 2*cdelta * [-(nbars - 1) / 2 : (nbars - 1) / 2];
@@ -223,7 +225,7 @@
       hax = newplot (hax);
 
       htmp = bars (hax, vertical, x, y, xb, yb, gwidth, group,
-                   have_line_spec, bv, newargs{:});
+                   have_line_spec | ishist, bv, newargs{:});
 
       if (! ishold ())
         if (numel (x(:,1)) <= 15 && all (x(:,1) == fix (x(:,1))))
@@ -241,7 +243,7 @@
         else
           set (hax, "clim", [0 1], "ylimmode", "manual");
         endif
-        set (hax, "box", "on", "layer", "top");
+        set (hax, "box", "on", "layer", "top", "climmode", "auto");
       endif
     unwind_protect_cleanup
       if (! isempty (oldfig))
@@ -279,14 +281,14 @@
         color = __next_line_color__ ();
         h = patch (hax, xb(:,:,i), yb(:,:,i), "FaceColor", color, "parent", hg);
       else
-        h = patch (hax, xb(:,:,i), yb(:,:,i), "parent", hg);
+        h = patch (hax, xb(:,:,i), yb(:,:,i), "cdata", i, "parent", hg);
       endif
     else
       if (! have_color_spec)
         color = __next_line_color__ ();
         h = patch (hax, yb(:,:,i), xb(:,:,i), "FaceColor", color, "parent", hg);
       else
-        h = patch (hax, yb(:,:,i), xb(:,:,i), "parent", hg);
+        h = patch (hax, yb(:,:,i), xb(:,:,i), "cdata", i, "parent", hg);
       endif
     endif