# HG changeset patch # User Ben Abbott # Date 1245754677 -7200 # Node ID d5c5927d7d117e2427bf2aa509dadbcb0b868a77 # Parent dc56a38b5a64dee2cf19c33232b57702fd984f08 grid.m: Add missing semi-colon. Fix grid toggle. Allow minor grid when no minor tick. diff -r dc56a38b5a64 -r d5c5927d7d11 scripts/ChangeLog --- a/scripts/ChangeLog Tue Jun 23 12:57:57 2009 +0200 +++ b/scripts/ChangeLog Tue Jun 23 12:57:57 2009 +0200 @@ -1,3 +1,11 @@ +2009-06-22 Ben Abbott + + * 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 * statistics/base/var.m: Return zero for scalar case. Handle diff -r dc56a38b5a64 -r d5c5927d7d11 scripts/plot/__go_draw_axes__.m --- a/scripts/plot/__go_draw_axes__.m Tue Jun 23 12:57:57 2009 +0200 +++ b/scripts/plot/__go_draw_axes__.m Tue Jun 23 12:57:57 2009 +0200 @@ -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 diff -r dc56a38b5a64 -r d5c5927d7d11 scripts/plot/grid.m --- a/scripts/plot/grid.m Tue Jun 23 12:57:57 2009 +0200 +++ b/scripts/plot/grid.m Tue Jun 23 12:57:57 2009 +0200 @@ -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") +