# HG changeset patch
# User Markus Mützel <markus.muetzel@gmx.de>
# Date 1472576374 -7200
#      Tue Aug 30 18:59:34 2016 +0200
# Node ID 53884c6887792c10eb4667bf0dff91e9f125fe24
# Parent  dc4e2203cd159a0e2a1c7f8f4e6ab2ad426abcf8
Do not change grid for semilog plots on second call of "grid on" (bug #48533)

* grid.m: Do not change grid for semilogx or semilogy plots on second
call of "grid on". Add test for semilog plots. Add demo with only minor
grid lines (no major grid).

diff -r dc4e2203cd15 -r 53884c688779 scripts/plot/appearance/grid.m
--- a/scripts/plot/appearance/grid.m	Mon Aug 29 14:32:22 2016 -0700
+++ b/scripts/plot/appearance/grid.m	Tue Aug 30 18:59:34 2016 +0200
@@ -62,11 +62,15 @@
   grid_on = any (strcmp (get (hax, {"xgrid", "ygrid", "zgrid"}), "on"));
 
   minor_on = any (strcmp (get (hax, {"xminorgrid", "yminorgrid", "zminorgrid"}),
-                         "on"));
+                         "on") &
+                  ! strcmp (get (hax, {"xscale", "yscale", "zscale"}), "log"));
 
   minor_auto = true;
   if (nargs == 0)
     grid_on = ! grid_on;
+    if (! grid_on)
+      minor_auto = false;
+    endif
   else
     arg1 = varargin{1};
     if (! ischar (arg1))
@@ -78,6 +82,8 @@
       minor_auto = false;
     elseif (strcmpi (arg1, "on"))
       grid_on = true;
+      minor_on = false;
+      minor_auto = true;
     elseif (strcmpi (arg1, "minor"))
       minor_auto = false;
       if (nargs == 2)
@@ -162,8 +168,21 @@
 %!  grid minor;
 %!  title ("grid minor");
 
+%!demo
+%! ## Display minor grid lines at major ticks
+%! clf;
+%! subplot (1,2,1)
+%!  plot (1:10);
+%!  set (gca, 'xminorgrid', 'on')
+%!  set (gca, 'yminorgrid', 'on')
+%! subplot (1,2,2)
+%!  semilogy (1:100);
+%!  set (gca, 'xminorgrid', 'on')
+%!  set (gca, 'yminorgrid', 'on')
+
+
 ## linear scaling
-%!test
+%!test <48533>
 %! hf = figure ("visible", "off");
 %! unwind_protect
 %!   hax = axes ();
@@ -221,3 +240,69 @@
 %!   close (hf);
 %! end_unwind_protect
 
+## semilog scaling
+%!test <48533>
+%! hf = figure ("visible", "off");
+%! unwind_protect
+%!   hax = axes ();
+%!   semilogy (1:100);
+%!   grid on
+%!   assert (get (hax, "xgrid"), "on");
+%!   assert (get (hax, "ygrid"), "on");
+%!   assert (get (hax, "zgrid"), "on");
+%!   assert (get (hax, "xminorgrid"), "off");
+%!   assert (get (hax, "yminorgrid"), "on");
+%!   assert (get (hax, "zminorgrid"), "off");
+%!   grid on
+%!   assert (get (hax, "xgrid"), "on");
+%!   assert (get (hax, "ygrid"), "on");
+%!   assert (get (hax, "zgrid"), "on");
+%!   assert (get (hax, "xminorgrid"), "off");
+%!   assert (get (hax, "yminorgrid"), "on");
+%!   assert (get (hax, "zminorgrid"), "off");
+%!   grid minor
+%!   assert (get (hax, "xgrid"), "on");
+%!   assert (get (hax, "ygrid"), "on");
+%!   assert (get (hax, "zgrid"), "on");
+%!   assert (get (hax, "xminorgrid"), "on");
+%!   assert (get (hax, "yminorgrid"), "on");
+%!   assert (get (hax, "zminorgrid"), "on");
+%!   grid off
+%!   assert (get (hax, "xgrid"), "off");
+%!   assert (get (hax, "ygrid"), "off");
+%!   assert (get (hax, "zgrid"), "off");
+%!   assert (get (hax, "xminorgrid"), "off");
+%!   assert (get (hax, "yminorgrid"), "off");
+%!   assert (get (hax, "zminorgrid"), "off");
+%!   grid minor
+%!   assert (get (hax, "xgrid"), "off");
+%!   assert (get (hax, "ygrid"), "off");
+%!   assert (get (hax, "zgrid"), "off");
+%!   assert (get (hax, "xminorgrid"), "on");
+%!   assert (get (hax, "yminorgrid"), "on");
+%!   assert (get (hax, "zminorgrid"), "on");
+%!   grid minor
+%!   assert (get (hax, "xgrid"), "off");
+%!   assert (get (hax, "ygrid"), "off");
+%!   assert (get (hax, "zgrid"), "off");
+%!   assert (get (hax, "xminorgrid"), "off");
+%!   assert (get (hax, "yminorgrid"), "off");
+%!   assert (get (hax, "zminorgrid"), "off");
+%!   grid
+%!   assert (get (hax, "xgrid"), "on");
+%!   assert (get (hax, "ygrid"), "on");
+%!   assert (get (hax, "zgrid"), "on");
+%!   assert (get (hax, "xminorgrid"), "off");
+%!   assert (get (hax, "yminorgrid"), "on");
+%!   assert (get (hax, "zminorgrid"), "off");
+%!   grid
+%!   assert (get (hax, "xgrid"), "off");
+%!   assert (get (hax, "ygrid"), "off");
+%!   assert (get (hax, "zgrid"), "off");
+%!   assert (get (hax, "xminorgrid"), "off");
+%!   assert (get (hax, "yminorgrid"), "off");
+%!   assert (get (hax, "zminorgrid"), "off");
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect
+
