changelog shortlog tags changeset files revisions annotate raw

scripts/plot/grid.m

changeset 10289: 4b124317dc38
parent:eb63fbe60fab
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (50 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2003, 2004,
2## 2005, 2006, 2007, 2008, 2009 John W. Eaton
3##
4## This file is part of Octave.
5##
6## Octave is free software; you can redistribute it and/or modify it
7## under the terms of the GNU General Public License as published by
8## the Free Software Foundation; either version 3 of the License, or (at
9## your option) any later version.
10##
11## Octave is distributed in the hope that it will be useful, but
12## WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14## General Public License for more details.
15##
16## You should have received a copy of the GNU General Public License
17## along with Octave; see the file COPYING. If not, see
18## <http://www.gnu.org/licenses/>.
19
20## -*- texinfo -*-
21## @deftypefn {Function File} {} grid (@var{arg})
22## @deftypefnx {Function File} {} grid ("minor", @var{arg2})
23## @deftypefnx {Function File} {} grid (@var{hax}, @dots{})
24## Force the display of a grid on the plot.
25## The argument may be either @code{"on"}, or @code{"off"}.
26## If it is omitted, the current grid state is toggled.
27##
28## If @var{arg} is @code{"minor"} then the minor grid is toggled. When
29## using a minor grid a second argument @var{arg2} is allowed, which can
30## be either @code{"on"} or @code{"off"} to explicitly set the state of
31## the minor grid.
32##
33## If the first argument is an axis handle, @var{hax}, operate on the
34## specified axis object.
35## @seealso{plot}
36## @end deftypefn
37
38## Author: jwe
39
40function grid (varargin)
41
42 [ax, varargin, nargs] = __plt_get_axis_arg__ ("grid", varargin{:});
43
44 grid_on = (strcmp (get (ax, "xgrid"), "on")
45 && strcmp (get (ax, "ygrid"), "on")
46 && strcmp (get (ax, "zgrid"), "on"));
47
48 minor_on = (strcmp (get (ax, "xminorgrid"), "on")
49 && strcmp (get (ax, "yminorgrid"), "on")
50 && strcmp (get (ax, "zminorgrid"), "on"));
51
52 if (nargs > 2)
53 print_usage ();
54 elseif (nargs == 0)
55 grid_on = ! grid_on;
56 else
57 x = varargin{1};
58 if (ischar (x))
59 if (strcmpi (x, "off"))
60 grid_on = false;
61 elseif (strcmpi (x, "on"))
62 grid_on = true;
63 elseif (strcmpi (x, "minor"))
64 if (nargs == 2)
65 x2 = varargin{2};
66 if (strcmpi (x2, "on"))
67 minor_on = true;
68 grid_on = true;
69 elseif (strcmpi (x2, "off"))
70 minor_on = false;
71 else
72 print_usage ();
73 endif
74 else
75 minor_on = ! minor_on;
76 if (minor_on)
77 grid_on = true;
78 endif
79 endif
80 else
81 print_usage ();
82 endif
83 else
84 error ("grid: argument must be a string");
85 endif
86 endif
87
88 if (grid_on)
89 set (ax, "xgrid", "on", "ygrid", "on", "zgrid", "on");
90 if (minor_on)
91 set (ax, "xminorgrid", "on", "yminorgrid", "on", "zminorgrid", "on");
92 else
93 set (ax, "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off");
94 endif
95 else
96 set (ax, "xgrid", "off", "ygrid", "off", "zgrid", "off");
97 set (ax, "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off");
98 endif
99
100endfunction
101
102%!demo
103%! clf
104%! subplot (2,2,1)
105%! plot (1:100)
106%! grid minor
107%! grid minor
108%! grid
109%! title ("no grid")
110%! subplot (2,2,2)
111%! plot (1:100)
112%! grid
113%! title ("grid on")
114%! subplot (2,2,3)
115%! plot (1:100)
116%! grid minor
117%! title ("grid minor")
118%! subplot (2,2,4)
119%! semilogy (1:100)
120%! grid minor
121%! title ("grid minor")
122