Mercurial > hg > octave-lyh
annotate scripts/plot/grid.m @ 17535:c12c688a35ed default tip lyh
Fix warnings
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 17:43:27 +0800 |
parents | bc924baa2c4e |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1 ## Copyright (C) 1993-2012 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 -*- |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17085
diff
changeset
|
20 ## @deftypefn {Command} {} grid |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17085
diff
changeset
|
21 ## @deftypefnx {Command} {} grid on |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17085
diff
changeset
|
22 ## @deftypefnx {Command} {} grid off |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17085
diff
changeset
|
23 ## @deftypefnx {Command} {} grid minor |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17085
diff
changeset
|
24 ## @deftypefnx {Command} {} grid minor on |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17085
diff
changeset
|
25 ## @deftypefnx {Command} {} grid minor off |
8528 | 26 ## @deftypefnx {Function File} {} grid (@var{hax}, @dots{}) |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17085
diff
changeset
|
27 ## Control the display of plot grid lines. |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
28 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
29 ## The function state input may be either @qcode{"on"} or @qcode{"off"}. |
8528 | 30 ## If it is omitted, the current grid state is toggled. |
5727 | 31 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17126
diff
changeset
|
32 ## When the first argument is @qcode{"minor"} all subsequent commands |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
33 ## modify the minor grid rather than the major grid. |
8528 | 34 ## |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17085
diff
changeset
|
35 ## If the first argument @var{hax} is an axes handle, then operate on |
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17085
diff
changeset
|
36 ## this axis rather than the current axes returned by @code{gca}. |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
37 ## |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
38 ## To control the grid lines for an individual axis use the @code{set} |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17085
diff
changeset
|
39 ## function. For example: |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
40 ## |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
41 ## @example |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
42 ## set (gca, "ygrid", "on"); |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
43 ## @end example |
17126
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
17085
diff
changeset
|
44 ## @seealso{axis, box} |
3368 | 45 ## @end deftypefn |
4 | 46 |
2314 | 47 ## Author: jwe |
48 | |
7215 | 49 function grid (varargin) |
5727 | 50 |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
51 [hax, varargin, nargs] = __plt_get_axis_arg__ ("grid", varargin{:}); |
6257 | 52 |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
53 if (isempty (hax)) |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
54 hax = gca (); |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
55 endif |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
56 |
8424
a84d71abdc5b
grid.m: handle minor grid option
Doug Stewart <dastew@sympatico.ca>
parents:
8190
diff
changeset
|
57 if (nargs > 2) |
7215 | 58 print_usage (); |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
59 endif |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
60 |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
61 grid_on = ( strcmp (get (hax, "xgrid"), "on") |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
62 && strcmp (get (hax, "ygrid"), "on") |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
63 && strcmp (get (hax, "zgrid"), "on")); |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
64 |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
65 minor_on = ( strcmp (get (hax, "xminorgrid"), "on") |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
66 && strcmp (get (hax, "yminorgrid"), "on") |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
67 && strcmp (get (hax, "zminorgrid"), "on")); |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
68 |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
69 if (nargs == 0) |
7215 | 70 grid_on = ! grid_on; |
6257 | 71 else |
7215 | 72 x = varargin{1}; |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
73 if (! ischar (x)) |
17085
d3ebc3f9bdbf
doc update for grid and subplot
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
17049
diff
changeset
|
74 error ("grid: argument 1 must be an axis handle or a string"); |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
75 endif |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
76 if (strcmpi (x, "off")) |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
77 grid_on = false; |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
78 elseif (strcmpi (x, "on")) |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
79 grid_on = true; |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
80 elseif (strcmpi (x, "minor")) |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
81 if (nargs == 2) |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
82 x2 = varargin{2}; |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
83 if (strcmpi (x2, "on")) |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
84 minor_on = true; |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
85 grid_on = true; |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
86 elseif (strcmpi (x2, "off")) |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
87 minor_on = false; |
10549 | 88 else |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
89 print_usage (); |
10549 | 90 endif |
4 | 91 else |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
92 minor_on = ! minor_on; |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
93 if (minor_on) |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
94 grid_on = true; |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
95 endif |
4 | 96 endif |
97 else | |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
98 print_usage (); |
4 | 99 endif |
6257 | 100 endif |
101 | |
102 if (grid_on) | |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
103 set (hax, "xgrid", "on", "ygrid", "on", "zgrid", "on"); |
6257 | 104 if (minor_on) |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
105 set (hax, "xminorgrid", "on", "yminorgrid", "on", "zminorgrid", "on"); |
5727 | 106 else |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
107 set (hax, "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off"); |
6257 | 108 endif |
4 | 109 else |
17049
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
110 set (hax, "xgrid", "off", "ygrid", "off", "zgrid", "off", |
0322e057697f
hold.m, grid.m, box.m: Update to use new __plt_get_axis_arg__.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
14245
diff
changeset
|
111 "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off"); |
5152 | 112 endif |
113 | |
4 | 114 endfunction |
9374
6a035159ba0e
grid.m: Add missing semi-colon. Fix grid toggle. Allow minor grid when no minor tick.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
115 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
116 |
9374
6a035159ba0e
grid.m: Add missing semi-colon. Fix grid toggle. Allow minor grid when no minor tick.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
117 %!demo |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
118 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
119 %! subplot (2,2,1); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
120 %! plot (1:100); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
121 %! grid off; |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
122 %! title ('no grid'); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
123 %! subplot (2,2,2); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
124 %! plot (1:100); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
125 %! grid on; |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
126 %! title ('grid on'); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
127 %! subplot (2,2,3); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
128 %! plot (1:100); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
129 %! grid minor; |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
130 %! title ('grid minor'); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
131 %! subplot (2,2,4); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
132 %! semilogy (1:100); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
133 %! grid minor; |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
134 %! title ('grid minor'); |
9374
6a035159ba0e
grid.m: Add missing semi-colon. Fix grid toggle. Allow minor grid when no minor tick.
Ben Abbott <bpabbott@mac.com>
parents:
8920
diff
changeset
|
135 |