Mercurial > hg > octave-nkf
annotate scripts/plot/grid.m @ 17520:8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
* scripts/plot/grid.m: When switching grid on, turn minor grid on
for log scale axes.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 30 Sep 2013 19:55:51 -0700 |
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 -*- |
17122
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{}) |
17122
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 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17122
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 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17122
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 ## |
17122
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} |
17122
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 |
17122
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 |
17520
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
69 minor_auto = true; |
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
|
70 if (nargs == 0) |
7215 | 71 grid_on = ! grid_on; |
6257 | 72 else |
17520
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
73 arg1 = varargin{1}; |
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
74 if (! ischar (arg1)) |
17085
d3ebc3f9bdbf
doc update for grid and subplot
Michael Godfrey <michaeldgodfrey@gmail.com>
parents:
17049
diff
changeset
|
75 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
|
76 endif |
17520
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
77 if (strcmpi (arg1, "off")) |
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
|
78 grid_on = false; |
17520
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
79 elseif (strcmpi (arg1, "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
|
80 grid_on = true; |
17520
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
81 elseif (strcmpi (arg1, "minor")) |
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
82 minor_auto = false; |
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
|
83 if (nargs == 2) |
17520
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
84 arg2 = varargin{2}; |
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
85 if (strcmpi (arg2, "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
|
86 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
|
87 grid_on = true; |
17520
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
88 elseif (strcmpi (arg2, "off")) |
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 minor_on = false; |
10549 | 90 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
|
91 print_usage (); |
10549 | 92 endif |
4 | 93 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
|
94 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
|
95 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
|
96 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
|
97 endif |
4 | 98 endif |
99 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
|
100 print_usage (); |
4 | 101 endif |
6257 | 102 endif |
103 | |
104 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
|
105 set (hax, "xgrid", "on", "ygrid", "on", "zgrid", "on"); |
6257 | 106 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
|
107 set (hax, "xminorgrid", "on", "yminorgrid", "on", "zminorgrid", "on"); |
17520
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
108 elseif (minor_auto) |
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
109 xmg = ifelse (strcmp (get (hax, "xscale"), "log"), "on", "off"); |
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
110 ymg = ifelse (strcmp (get (hax, "yscale"), "log"), "on", "off"); |
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
111 zmg = ifelse (strcmp (get (hax, "zscale"), "log"), "on", "off"); |
8a303b01cdd0
grid.m: 'grid on' now also turns on minor grid for log scale axes.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
112 set (hax, "xminorgrid", xmg, "yminorgrid", ymg, "zminorgrid", zmg); |
5727 | 113 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
|
114 set (hax, "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off"); |
6257 | 115 endif |
4 | 116 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
|
117 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
|
118 "xminorgrid", "off", "yminorgrid", "off", "zminorgrid", "off"); |
5152 | 119 endif |
120 | |
4 | 121 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
|
122 |
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 |
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
|
124 %!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
|
125 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
126 %! 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
|
127 %! 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
|
128 %! grid off; |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
129 %! 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
|
130 %! 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
|
131 %! 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
|
132 %! grid on; |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
133 %! 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
|
134 %! 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
|
135 %! 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
|
136 %! grid minor; |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
137 %! 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
|
138 %! 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
|
139 %! 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
|
140 %! grid minor; |
14245
4506eade9f04
Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
141 %! 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
|
142 |