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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
2313
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
245
|
18 |
3368
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} grid (@var{arg}) |
5727
|
21 ## @deftypefnx {Function File} {} grid ("minor", @var{arg2}) |
6257
|
22 ## Force the display of a grid on the plot. |
3368
|
23 ## The argument may be either @code{"on"} or @code{"off"}. If it is |
6653
|
24 ## omitted, the current grid state is toggled. |
5727
|
25 ## |
6895
|
26 ## If @var{arg} is @code{"minor"} then the minor grid is toggled. When |
5727
|
27 ## using a minor grid a second argument @var{arg2} is allowed, which can |
|
28 ## be either @code{"on"} or @code{"off"} to explicitly set the state of |
6257
|
29 ## the minor grid. |
6895
|
30 ## @seealso{plot} |
3368
|
31 ## @end deftypefn |
4
|
32 |
2314
|
33 ## Author: jwe |
|
34 |
4264
|
35 ## PKG_ADD: mark_as_command grid |
|
36 |
5727
|
37 function grid (x, y) |
|
38 |
|
39 persistent grid_on = false; |
|
40 persistent minor_on = false; |
6257
|
41 |
|
42 nargs = nargin; |
4
|
43 |
6257
|
44 if (nargs == 2) |
|
45 if (ishandle (x)) |
|
46 ax = x; |
|
47 x = y; |
|
48 nargs--; |
6828
|
49 if (! strcmp (get (ax, "type"), "axes")) |
6257
|
50 error ("grid: expecting first argument to be an axes object"); |
|
51 endif |
|
52 else |
|
53 print_usage (); |
|
54 endif |
|
55 else |
|
56 ax = gca (); |
|
57 endif |
5152
|
58 |
6257
|
59 if (nargs == 0) |
5727
|
60 grid_on = ! grid_on; |
6257
|
61 elseif (nargs == 1) |
5443
|
62 if (ischar (x)) |
4
|
63 if (strcmp ("off", x)) |
5727
|
64 grid_on = false; |
4
|
65 elseif (strcmp ("on", x)) |
5727
|
66 grid_on = true; |
|
67 elseif (strcmp ("minor", x)) |
|
68 minor_on = ! minor_on; |
|
69 if (minor_on) |
6257
|
70 grid_on = true; |
5727
|
71 endif |
4
|
72 else |
6046
|
73 print_usage (); |
4
|
74 endif |
|
75 else |
904
|
76 error ("grid: argument must be a string"); |
4
|
77 endif |
6257
|
78 else |
|
79 print_usage (); |
|
80 endif |
|
81 |
|
82 if (grid_on) |
|
83 set (ax, "xgrid", "on", "ygrid", "on", "zgrid", "on"); |
|
84 if (minor_on) |
|
85 set (ax, "xminorgrid", "on", "yminorgrid", "on", "zminorgrid", "on"); |
5727
|
86 else |
6257
|
87 set (ax, "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off"); |
|
88 endif |
4
|
89 else |
6257
|
90 set (ax, "xgrid", "off", "ygrid", "off", "zgrid", "off"); |
|
91 set (ax, "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off"); |
5152
|
92 endif |
|
93 |
4
|
94 endfunction |