2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
245
|
19 |
3368
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} grid (@var{arg}) |
5727
|
22 ## @deftypefnx {Function File} {} grid ("minor", @var{arg2}) |
3368
|
23 ## For two-dimensional plotting, force the display of a grid on the plot. |
|
24 ## The argument may be either @code{"on"} or @code{"off"}. If it is |
5727
|
25 ## omitted, the the current grid state is toggled. |
|
26 ## |
|
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 |
|
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 |
|
31 ## number of minor grid lines. |
5642
|
32 ## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour, |
|
33 ## bar, stairs, replot, xlabel, ylabel, title} |
3368
|
34 ## @end deftypefn |
4
|
35 |
2314
|
36 ## Author: jwe |
|
37 |
4264
|
38 ## PKG_ADD: mark_as_command grid |
|
39 |
5727
|
40 function grid (x, y) |
|
41 |
|
42 persistent grid_on = false; |
|
43 persistent minor_on = false; |
|
44 persistent minor_tics = 5; |
4
|
45 |
5152
|
46 do_replot = false; |
|
47 |
4
|
48 if (nargin == 0) |
5727
|
49 grid_on = ! grid_on; |
|
50 if (grid_on) |
|
51 __gnuplot_raw__ ("set grid;\n"); |
|
52 else |
|
53 __gnuplot_raw__ ("set nogrid;\n"); |
|
54 endif |
5152
|
55 do_replot = true; |
4
|
56 elseif (nargin == 1) |
5443
|
57 if (ischar (x)) |
4
|
58 if (strcmp ("off", x)) |
5252
|
59 __gnuplot_raw__ ("set nogrid;\n"); |
5727
|
60 grid_on = false; |
5152
|
61 do_replot = true; |
4
|
62 elseif (strcmp ("on", x)) |
5605
|
63 __gnuplot_raw__ ("set grid;\n"); |
5727
|
64 grid_on = true; |
|
65 do_replot = true; |
|
66 elseif (strcmp ("minor", x)) |
|
67 minor_on = ! minor_on; |
|
68 if (minor_on) |
|
69 cmd = sprintf ("set mxtics %d;\n", minor_tics); |
|
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 |
5152
|
83 do_replot = true; |
4
|
84 else |
6046
|
85 print_usage (); |
4
|
86 endif |
|
87 else |
904
|
88 error ("grid: argument must be a string"); |
4
|
89 endif |
5727
|
90 elseif (nargin == 2) |
|
91 if (ischar (x)) |
|
92 if (strcmp ("minor", x)) |
|
93 d = str2num (y); |
|
94 if (isempty (d)) |
|
95 if (strcmp ("off", y)) |
|
96 if (grid_on) |
|
97 __gnuplot_raw__ ("set grid xtics nomxtics ytics nomxtics;\n"); |
|
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 |
6046
|
110 print_usage (); |
5727
|
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 |
6046
|
124 print_usage ();; |
5727
|
125 endif |
|
126 endif |
|
127 else |
6046
|
128 print_usage ();; |
5727
|
129 endif |
|
130 else |
6046
|
131 print_usage ();; |
5727
|
132 endif |
4
|
133 else |
6046
|
134 print_usage ();; |
5727
|
135 endif |
4
|
136 |
5152
|
137 if (do_replot && automatic_replot) |
5493
|
138 replot (); |
5152
|
139 endif |
|
140 |
4
|
141 endfunction |