Mercurial > hg > octave-nkf
comparison scripts/plot/grid.m @ 6257:44c91c5dfe1d
[project @ 2007-01-30 19:16:52 by jwe]
author | jwe |
---|---|
date | Tue, 30 Jan 2007 19:16:55 +0000 |
parents | 34f96dd5441b |
children | 2110cc251779 |
comparison
equal
deleted
inserted
replaced
6256:83949ae13b2c | 6257:44c91c5dfe1d |
---|---|
18 ## 02110-1301, USA. | 18 ## 02110-1301, USA. |
19 | 19 |
20 ## -*- texinfo -*- | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} grid (@var{arg}) | 21 ## @deftypefn {Function File} {} grid (@var{arg}) |
22 ## @deftypefnx {Function File} {} grid ("minor", @var{arg2}) | 22 ## @deftypefnx {Function File} {} grid ("minor", @var{arg2}) |
23 ## For two-dimensional plotting, force the display of a grid on the plot. | 23 ## Force the display of a grid on the plot. |
24 ## The argument may be either @code{"on"} or @code{"off"}. If it is | 24 ## The argument may be either @code{"on"} or @code{"off"}. If it is |
25 ## omitted, the the current grid state is toggled. | 25 ## omitted, the the current grid state is toggled. |
26 ## | 26 ## |
27 ## If @var{arg} is @code{"minor"} then the minor grid is toggled. When | 27 ## If @var{arg} is @code{"minor"} then the minor grid is toggled. When |
28 ## using a minor grid a second argument @var{arg2} is allowed, which can | 28 ## using a minor grid a second argument @var{arg2} is allowed, which can |
29 ## be either @code{"on"} or @code{"off"} to explicitly set the state of | 29 ## be either @code{"on"} or @code{"off"} to explicitly set the state of |
30 ## the minor grid, or alternatively a positive integer specifying the | 30 ## the minor grid. |
31 ## number of minor grid lines. | |
32 ## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour, | 31 ## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour, |
33 ## bar, stairs, replot, xlabel, ylabel, title} | 32 ## bar, stairs, replot, xlabel, ylabel, title} |
34 ## @end deftypefn | 33 ## @end deftypefn |
35 | 34 |
36 ## Author: jwe | 35 ## Author: jwe |
39 | 38 |
40 function grid (x, y) | 39 function grid (x, y) |
41 | 40 |
42 persistent grid_on = false; | 41 persistent grid_on = false; |
43 persistent minor_on = false; | 42 persistent minor_on = false; |
44 persistent minor_tics = 5; | |
45 | 43 |
46 do_replot = false; | 44 nargs = nargin; |
47 | 45 |
48 if (nargin == 0) | 46 if (nargs == 2) |
47 if (ishandle (x)) | |
48 ax = x; | |
49 obj = get (x); | |
50 x = y; | |
51 nargs--; | |
52 if (! strcmp (obj.type, "axes")) | |
53 error ("grid: expecting first argument to be an axes object"); | |
54 endif | |
55 else | |
56 print_usage (); | |
57 endif | |
58 else | |
59 ax = gca (); | |
60 endif | |
61 | |
62 if (nargs == 0) | |
49 grid_on = ! grid_on; | 63 grid_on = ! grid_on; |
50 if (grid_on) | 64 elseif (nargs == 1) |
51 __gnuplot_raw__ ("set grid;\n"); | |
52 else | |
53 __gnuplot_raw__ ("set nogrid;\n"); | |
54 endif | |
55 do_replot = true; | |
56 elseif (nargin == 1) | |
57 if (ischar (x)) | 65 if (ischar (x)) |
58 if (strcmp ("off", x)) | 66 if (strcmp ("off", x)) |
59 __gnuplot_raw__ ("set nogrid;\n"); | |
60 grid_on = false; | 67 grid_on = false; |
61 do_replot = true; | |
62 elseif (strcmp ("on", x)) | 68 elseif (strcmp ("on", x)) |
63 __gnuplot_raw__ ("set grid;\n"); | |
64 grid_on = true; | 69 grid_on = true; |
65 do_replot = true; | |
66 elseif (strcmp ("minor", x)) | 70 elseif (strcmp ("minor", x)) |
67 minor_on = ! minor_on; | 71 minor_on = ! minor_on; |
68 if (minor_on) | 72 if (minor_on) |
69 cmd = sprintf ("set mxtics %d;\n", minor_tics); | 73 grid_on = true; |
70 __gnuplot_raw__ (cmd); | |
71 cmd = sprintf ("set mytics %d;\n", minor_tics); | |
72 __gnuplot_raw__ (cmd); | |
73 __gnuplot_raw__ ("set grid xtics mxtics ytics mxtics;\n"); | |
74 minor_on = true; | |
75 else | |
76 if (grid_on) | |
77 __gnuplot_raw__ ("set grid xtics nomxtics ytics nomxtics;\n"); | |
78 else | |
79 __gnuplot_raw__ ("set grid noxtics nomxtics noytics nomxtics;\n"); | |
80 endif | |
81 minor_on = false; | |
82 endif | 74 endif |
83 do_replot = true; | |
84 else | 75 else |
85 print_usage (); | 76 print_usage (); |
86 endif | 77 endif |
87 else | 78 else |
88 error ("grid: argument must be a string"); | 79 error ("grid: argument must be a string"); |
89 endif | 80 endif |
90 elseif (nargin == 2) | 81 else |
91 if (ischar (x)) | 82 print_usage (); |
92 if (strcmp ("minor", x)) | 83 endif |
93 d = str2num (y); | 84 |
94 if (isempty (d)) | 85 if (grid_on) |
95 if (strcmp ("off", y)) | 86 set (ax, "xgrid", "on", "ygrid", "on", "zgrid", "on"); |
96 if (grid_on) | 87 if (minor_on) |
97 __gnuplot_raw__ ("set grid xtics nomxtics ytics nomxtics;\n"); | 88 set (ax, "xminorgrid", "on", "yminorgrid", "on", "zminorgrid", "on"); |
98 else | |
99 __gnuplot_raw__ ("set grid noxtics nomxtics noytics nomxtics;\n"); | |
100 endif | |
101 minor_on = false; | |
102 elseif (strcmp ("on", y)) | |
103 cmd = sprintf ("set mxtics %d;\n", minor_tics); | |
104 __gnuplot_raw__ (cmd); | |
105 cmd = sprintf ("set mytics %d;\n", minor_tics); | |
106 __gnuplot_raw__ (cmd); | |
107 __gnuplot_raw__ ("set grid xtics mxtics ytics mxtics;\n"); | |
108 minor_on = true; | |
109 else | |
110 print_usage (); | |
111 endif | |
112 do_replot = true; | |
113 else | |
114 if (isscalar(d) && ! isnan (d) && ! isinf (d)) | |
115 minor_tics = max (floor (d), 0); | |
116 cmd = sprintf ("set mxtics %d;\n", minor_tics); | |
117 __gnuplot_raw__ (cmd); | |
118 cmd = sprintf("set mytics %d;\n", minor_tics); | |
119 __gnuplot_raw__ (cmd); | |
120 __gnuplot_raw__ ("set grid xtics mxtics ytics mxtics;\n"); | |
121 minor_on = true; | |
122 do_replot = true; | |
123 else | |
124 print_usage ();; | |
125 endif | |
126 endif | |
127 else | |
128 print_usage ();; | |
129 endif | |
130 else | 89 else |
131 print_usage ();; | 90 set (ax, "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off"); |
132 endif | 91 endif |
133 else | 92 else |
134 print_usage ();; | 93 set (ax, "xgrid", "off", "ygrid", "off", "zgrid", "off"); |
135 endif | 94 set (ax, "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off"); |
136 | |
137 if (do_replot && automatic_replot) | |
138 replot (); | |
139 endif | 95 endif |
140 | 96 |
141 endfunction | 97 endfunction |