changeset 12008:d5c5927d7d11 release-3-2-x

grid.m: Add missing semi-colon. Fix grid toggle. Allow minor grid when no minor tick.
author Ben Abbott <bpabbott@mac.com>
date Tue, 23 Jun 2009 12:57:57 +0200
parents dc56a38b5a64
children 4e2138bc1152
files scripts/ChangeLog scripts/plot/__go_draw_axes__.m scripts/plot/grid.m
diffstat 3 files changed, 72 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,11 @@
+2009-06-22  Ben Abbott <bpabbott@mac.com>
+
+	* plot/grid.m: Add missing semi-colon. Allow grid to be toggled
+	on/off for each axis independently. Gnuplot requires that minor
+	ticks accompany minor ticks. Add demo.
+	* plot/__go_draw_axes__.m: For {x,y,z}scale == 'log' use 10 minor
+	ticks.
+
 2009-06-22  John W. Eaton  <jwe@octave.org>
 
 	* statistics/base/var.m: Return zero for scalar case.  Handle
--- a/scripts/plot/__go_draw_axes__.m
+++ b/scripts/plot/__go_draw_axes__.m
@@ -226,7 +226,12 @@
 
     if (strcmpi (axis_obj.xminorgrid, "on"))
       have_grid = true;
-      fprintf (plot_stream, "set m%stics 5;\n", xaxisloc);
+      if (strcmp (axis_obj.xscale, "log"))
+	m = 10;
+      else
+	m = 5;
+      endif
+      fprintf (plot_stream, "set m%stics %d;\n", xaxisloc, m);
       fprintf (plot_stream, "set grid m%stics;\n", xaxisloc);
     else
       fprintf (plot_stream, "set grid nom%stics;\n", xaxisloc);
@@ -234,7 +239,12 @@
 
     if (strcmpi (axis_obj.yminorgrid, "on"))
       have_grid = true;
-      fprintf (plot_stream, "set m%stics 5;\n", yaxisloc);
+      if (strcmp (axis_obj.yscale, "log"))
+	m = 10;
+      else
+	m = 5;
+      endif
+      fprintf (plot_stream, "set m%stics %d;\n", yaxisloc, m);
       fprintf (plot_stream, "set grid m%stics;\n", yaxisloc);
     else
       fprintf (plot_stream, "set grid nom%stics;\n", yaxisloc);
@@ -242,7 +252,12 @@
 
     if (strcmpi (axis_obj.zminorgrid, "on"))
       have_grid = true;
-      fputs (plot_stream, "set mztics 5;\n");
+      if (strcmp (axis_obj.zscale, "log"))
+	m = 10;
+      else
+	m = 5;
+      endif
+      fprintf (plot_stream, "set mztics %d;\n", m);
       fputs (plot_stream, "set grid mztics;\n");
     else
       fputs (plot_stream, "set grid nomztics;\n");
@@ -1535,6 +1550,16 @@
   obj.yticklabel = ticklabel_to_cell (obj.yticklabel);
   obj.zticklabel = ticklabel_to_cell (obj.zticklabel);
 
+  if (strcmp (obj.xminorgrid, "on"))
+    obj.xminortick = "on";
+  endif
+  if (strcmp (obj.yminorgrid, "on"))
+    obj.yminortick = "on";
+  endif
+  if (strcmp (obj.zminorgrid, "on"))
+    obj.zminortick = "on";
+  endif
+
   [fontname, fontsize] = get_fontname_and_size (obj);
   fontspec = create_fontspec (fontname, fontsize, gnuplot_term);
 
@@ -1613,8 +1638,10 @@
   endif
   if (strcmp (scale, "log"))
     fmt = "10^{%T}";
+    num_mtics = 10;
   else
     fmt = "%g";
+    num_mtics = 5;
   endif
   colorspec = get_text_colorspec (color, mono);
   if (strcmpi (ticmode, "manual") || strcmpi (labelmode, "manual"))
@@ -1655,7 +1682,7 @@
 	endfor
 	fprintf (plot_stream, ") %s %s;\n", colorspec, fontspec);
  	if (strcmp (mtics, "on"))
-	  fprintf (plot_stream, "set m%stics 5;\n", ax);
+	  fprintf (plot_stream, "set m%stics %d;\n", ax, num_mtics);
 	else
 	  fprintf (plot_stream, "unset m%stics;\n", ax);
 	endif
@@ -1674,7 +1701,7 @@
       fprintf (plot_stream, " %.15g,", tics(1:end-1));
       fprintf (plot_stream, " %.15g) %s;\n", tics(end), fontspec);
       if (strcmp (mtics, "on"))
-        fprintf (plot_stream, "set m%stics 5;\n", ax);
+        fprintf (plot_stream, "set m%stics %d;\n", ax, num_mtics);
       else
 	fprintf (plot_stream, "unset m%stics;\n", ax);
       endif
@@ -1689,7 +1716,7 @@
 	       tickdir, ticklength, axispos, colorspec, fontspec);
     endif
     if (strcmp (mtics, "on"))
-      fprintf (plot_stream, "set m%stics 5;\n", ax);
+      fprintf (plot_stream, "set m%stics %d;\n", ax, num_mtics);
     else
       fprintf (plot_stream, "unset m%stics;\n", ax);
     endif
--- a/scripts/plot/grid.m
+++ b/scripts/plot/grid.m
@@ -39,10 +39,15 @@
 
 function grid (varargin)
 
-  persistent grid_on = false;
-  persistent minor_on = false;
+  [ax, varargin, nargs] = __plt_get_axis_arg__ ("grid", varargin{:});
 
-  [ax, varargin, nargs] = __plt_get_axis_arg__ ("grid", varargin{:});
+  grid_on = (strcmp (get (ax, "xgrid"), "on")
+             && strcmp (get (ax, "ygrid"), "on")
+             && strcmp (get (ax, "zgrid"), "on"));
+
+  minor_on = (strcmp (get (ax, "xminorgrid"), "on")
+              && strcmp (get (ax, "yminorgrid"), "on")
+              && strcmp (get (ax, "zminorgrid"), "on"));
 
   if (nargs > 2)
     print_usage ();
@@ -67,7 +72,7 @@
 	    print_usage ();
 	  endif
 	else
-	   minor_on = ! minor_on
+	   minor_on = ! minor_on;
 	   if (minor_on)
 	     grid_on = true;
 	   endif
@@ -93,3 +98,25 @@
   endif
 
 endfunction
+
+%!demo
+%! clf
+%! subplot (2,2,1)
+%! plot (1:100)
+%! grid minor
+%! grid minor
+%! grid
+%! title ("no grid")
+%! subplot (2,2,2)
+%! plot (1:100)
+%! grid
+%! title ("grid on")
+%! subplot (2,2,3)
+%! plot (1:100)
+%! grid minor
+%! title ("grid minor")
+%! subplot (2,2,4)
+%! semilogy (1:100)
+%! grid minor
+%! title ("grid minor")
+