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 ## |
|
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 |
6257
|
30 ## the minor grid. |
5642
|
31 ## @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour, |
6448
|
32 ## bar, stairs, xlabel, ylabel, title} |
3368
|
33 ## @end deftypefn |
4
|
34 |
2314
|
35 ## Author: jwe |
|
36 |
4264
|
37 ## PKG_ADD: mark_as_command grid |
|
38 |
5727
|
39 function grid (x, y) |
|
40 |
|
41 persistent grid_on = false; |
|
42 persistent minor_on = false; |
6257
|
43 |
|
44 nargs = nargin; |
4
|
45 |
6257
|
46 if (nargs == 2) |
|
47 if (ishandle (x)) |
|
48 ax = x; |
|
49 x = y; |
|
50 nargs--; |
6828
|
51 if (! strcmp (get (ax, "type"), "axes")) |
6257
|
52 error ("grid: expecting first argument to be an axes object"); |
|
53 endif |
|
54 else |
|
55 print_usage (); |
|
56 endif |
|
57 else |
|
58 ax = gca (); |
|
59 endif |
5152
|
60 |
6257
|
61 if (nargs == 0) |
5727
|
62 grid_on = ! grid_on; |
6257
|
63 elseif (nargs == 1) |
5443
|
64 if (ischar (x)) |
4
|
65 if (strcmp ("off", x)) |
5727
|
66 grid_on = false; |
4
|
67 elseif (strcmp ("on", x)) |
5727
|
68 grid_on = true; |
|
69 elseif (strcmp ("minor", x)) |
|
70 minor_on = ! minor_on; |
|
71 if (minor_on) |
6257
|
72 grid_on = true; |
5727
|
73 endif |
4
|
74 else |
6046
|
75 print_usage (); |
4
|
76 endif |
|
77 else |
904
|
78 error ("grid: argument must be a string"); |
4
|
79 endif |
6257
|
80 else |
|
81 print_usage (); |
|
82 endif |
|
83 |
|
84 if (grid_on) |
|
85 set (ax, "xgrid", "on", "ygrid", "on", "zgrid", "on"); |
|
86 if (minor_on) |
|
87 set (ax, "xminorgrid", "on", "yminorgrid", "on", "zminorgrid", "on"); |
5727
|
88 else |
6257
|
89 set (ax, "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off"); |
|
90 endif |
4
|
91 else |
6257
|
92 set (ax, "xgrid", "off", "ygrid", "off", "zgrid", "off"); |
|
93 set (ax, "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off"); |
5152
|
94 endif |
|
95 |
4
|
96 endfunction |