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}) |
6257
|
23 ## Force the display of a grid on the plot. |
3368
|
24 ## The argument may be either @code{"on"} or @code{"off"}. If it is |
6653
|
25 ## omitted, the current grid state is toggled. |
5727
|
26 ## |
6895
|
27 ## If @var{arg} is @code{"minor"} then the minor grid is toggled. When |
5727
|
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 |
6257
|
30 ## the minor grid. |
6895
|
31 ## @seealso{plot} |
3368
|
32 ## @end deftypefn |
4
|
33 |
2314
|
34 ## Author: jwe |
|
35 |
4264
|
36 ## PKG_ADD: mark_as_command grid |
|
37 |
5727
|
38 function grid (x, y) |
|
39 |
|
40 persistent grid_on = false; |
|
41 persistent minor_on = false; |
6257
|
42 |
|
43 nargs = nargin; |
4
|
44 |
6257
|
45 if (nargs == 2) |
|
46 if (ishandle (x)) |
|
47 ax = x; |
|
48 x = y; |
|
49 nargs--; |
6828
|
50 if (! strcmp (get (ax, "type"), "axes")) |
6257
|
51 error ("grid: expecting first argument to be an axes object"); |
|
52 endif |
|
53 else |
|
54 print_usage (); |
|
55 endif |
|
56 else |
|
57 ax = gca (); |
|
58 endif |
5152
|
59 |
6257
|
60 if (nargs == 0) |
5727
|
61 grid_on = ! grid_on; |
6257
|
62 elseif (nargs == 1) |
5443
|
63 if (ischar (x)) |
4
|
64 if (strcmp ("off", x)) |
5727
|
65 grid_on = false; |
4
|
66 elseif (strcmp ("on", x)) |
5727
|
67 grid_on = true; |
|
68 elseif (strcmp ("minor", x)) |
|
69 minor_on = ! minor_on; |
|
70 if (minor_on) |
6257
|
71 grid_on = true; |
5727
|
72 endif |
4
|
73 else |
6046
|
74 print_usage (); |
4
|
75 endif |
|
76 else |
904
|
77 error ("grid: argument must be a string"); |
4
|
78 endif |
6257
|
79 else |
|
80 print_usage (); |
|
81 endif |
|
82 |
|
83 if (grid_on) |
|
84 set (ax, "xgrid", "on", "ygrid", "on", "zgrid", "on"); |
|
85 if (minor_on) |
|
86 set (ax, "xminorgrid", "on", "yminorgrid", "on", "zminorgrid", "on"); |
5727
|
87 else |
6257
|
88 set (ax, "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off"); |
|
89 endif |
4
|
90 else |
6257
|
91 set (ax, "xgrid", "off", "ygrid", "off", "zgrid", "off"); |
|
92 set (ax, "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off"); |
5152
|
93 endif |
|
94 |
4
|
95 endfunction |