Mercurial > hg > octave-lyh
annotate scripts/time/datetick.m @ 16749:c9007267cbf5
Variation of color option layouts with columns packed to the left
* settings-dialog.cc (settings_dialog::read_workspace_colors,
settings_dialog::read_terminal_colors): Add 4 space characters to front of
color description. Set the column stretch for last (blank) column to 10.
author | Daniel J Sebald <daniel.sebald@ieee.org> |
---|---|
date | Tue, 11 Jun 2013 14:02:41 -0500 |
parents | 8899c785cc99 |
children | 73dd413f2c3e |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13082
diff
changeset
|
1 ## Copyright (C) 2008-2012 David Bateman |
8112 | 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 3 of the License, or (at | |
8 ## your option) 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, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10369
diff
changeset
|
20 ## @deftypefn {Function File} {} datetick () |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
21 ## @deftypefnx {Function File} {} datetick (@var{form}) |
8112 | 22 ## @deftypefnx {Function File} {} datetick (@var{axis}, @var{form}) |
23 ## @deftypefnx {Function File} {} datetick (@dots{}, "keeplimits") | |
24 ## @deftypefnx {Function File} {} datetick (@dots{}, "keepticks") | |
16094
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
25 ## @deftypefnx {Function File} {} datetick (@var{hax}, @dots{}) |
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
26 ## Add date formatted tick labels to an axis. The axis to apply the |
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
27 ## ticks to is determined by @var{axis} which can take the values "x", |
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
28 ## "y", or "z". The default value is "x". The formatting of the labels is |
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
29 ## determined by the variable @var{form}, which can either be a string or |
8899c785cc99
doc: Fix warnings associated with Texinfo 5.0 (bug #38392)
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
30 ## positive integer that @code{datestr} accepts. |
8112 | 31 ## @seealso{datenum, datestr} |
32 ## @end deftypefn | |
33 | |
34 function datetick (varargin) | |
35 | |
36 [h, varargin, nargin] = __plt_get_axis_arg__ ("datetick", varargin{:}); | |
37 | |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
38 oldh = gca (); |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
39 unwind_protect |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
40 axes (h); |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
41 __datetick__ (varargin{:}); |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
42 unwind_protect_cleanup |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
43 axes (oldh); |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
44 end_unwind_protect |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
45 |
8112 | 46 endfunction |
47 | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
48 |
8112 | 49 %!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
|
50 %! clf; |
8112 | 51 %! yr = 1900:10:2000; |
52 %! pop = [76.094, 92.407, 106.461, 123.077 131.954, 151.868, 179.979, ... | |
53 %! 203.984, 227.225, 249.623, 282.224]; | |
54 %! plot (datenum (yr, 1, 1), pop); | |
55 %! title ("US population (millions)"); | |
56 %! xlabel ("Year"); | |
57 %! datetick ("x", "YYYY"); | |
58 | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
59 %!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
|
60 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
61 %! yr = 1988:2:2002; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
62 %! yr = datenum (yr,1,1); |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
63 %! pr = [12.1 13.3 12.6 13.1 13.3 14.1 14.4 15.2]; |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
64 %! plot (yr, pr); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
65 %! xlabel ("year"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
66 %! ylabel ("average price"); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
67 %! ax = gca; |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
68 %! set (ax, "xtick", datenum (1990:5:2005,1,1)); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
69 %! datetick (2, "keepticks"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
70 %! set (ax, "ytick", 12:16); |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
71 |
13082
35c0b722d2e4
codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
72 ## Remove from test statistics. No real tests possible. |
35c0b722d2e4
codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
73 %!assert (1) |
35c0b722d2e4
codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
74 |
8112 | 75 function __datetick__ (varargin) |
76 | |
77 keeplimits = false; | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
78 keepticks = false; |
8112 | 79 idx = []; |
80 for i = 1 : nargin | |
81 arg = varargin {i}; | |
82 if (ischar (arg)) | |
83 if (strcmpi (arg, "keeplimits")) | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
84 keeplimits = true; |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
85 idx = [idx, i]; |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
86 elseif (strcmpi (arg, "keepticks")) |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
87 keepticks = true; |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
88 idx = [idx, i]; |
8112 | 89 endif |
90 endif | |
91 endfor | |
92 | |
93 varargin(idx) = []; | |
94 nargin = length (varargin); | |
95 form = []; | |
96 ax = "x"; | |
97 | |
98 if (nargin != 0) | |
99 arg = varargin{1}; | |
11149
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10793
diff
changeset
|
100 if (ischar (arg) && (strcmp (arg, "x") || strcmp (arg, "y") |
fe3c3dfc07eb
style fix: break lines before && and ||, not after
John W. Eaton <jwe@octave.org>
parents:
10793
diff
changeset
|
101 || strcmp (arg, "z"))) |
8112 | 102 ax = arg; |
103 if (nargin > 1) | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
104 form = varargin{2}; |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
105 varargin(1:2) = []; |
8112 | 106 else |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
107 varargin(1) = []; |
8112 | 108 endif |
109 else | |
110 form = arg; | |
111 varargin(1) = []; | |
112 endif | |
113 endif | |
114 | |
115 ## Don't publish the existence of this variable for use with dateaxis | |
116 if (length (varargin) > 0) | |
117 startdate = varargin{1}; | |
118 else | |
119 startdate = []; | |
120 endif | |
121 | |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
122 if (! isempty (form)) |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
123 if (isnumeric (form)) |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
124 if (! isscalar (form) || floor (form) != form || form < 0) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11294
diff
changeset
|
125 error ("datetick: expecting FORM argument to be a positive integer"); |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
126 endif |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
127 elseif (! ischar (form)) |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
128 error ("datetick: expecting valid date format string"); |
8112 | 129 endif |
130 endif | |
131 | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
132 if (keepticks) |
11294
e2a4f3478b7c
datetick.m: add missing semicolon
John W. Eaton <jwe@octave.org>
parents:
11149
diff
changeset
|
133 ticks = get (gca (), strcat (ax, "tick")); |
8112 | 134 else |
135 ## Need to do our own axis tick position calculation as | |
136 ## year, etc, don't fallback on nice datenum values. | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14665
diff
changeset
|
137 objs = findall (gca ()); |
8112 | 138 xmax = NaN; |
139 xmin = NaN; | |
140 for i = 1 : length (objs) | |
141 fld = get (objs (i)); | |
142 if (isfield (fld, strcat (ax, "data"))) | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
143 xdata = getfield (fld, strcat (ax, "data"))(:); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
144 xmin = min (xmin, min (xdata)); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
145 xmax = max (xmax, max (xdata)); |
8112 | 146 endif |
147 endfor | |
148 | |
149 if (isnan (xmin) || isnan (xmax)) | |
150 xmin = 0; | |
151 xmax = 1; | |
152 elseif (xmin == xmax) | |
153 xmax = xmin + 1; | |
154 endif | |
155 | |
156 N = 3; | |
157 if (xmax - xmin < N) | |
158 ## Day scale or less | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
159 if (xmax - xmin < N / 24 / 60 / 60) |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
160 scl = 1 / 24 / 60 / 60; |
14665
4f458e882516
Allow fractional months to datenum and correct a couple of typos in datetick (bug #36482)
David Bateman <dbateman@free.fr>
parents:
14552
diff
changeset
|
161 elseif (xmax - xmin < N / 24 / 60) |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
162 scl = 1 / 24 / 60; |
8112 | 163 else |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
164 scl = 1 / 24; |
8112 | 165 endif |
166 sep = __calc_tick_sep__ (xmin / scl , xmax / scl); | |
167 xmin = sep * floor (xmin / scl / sep); | |
168 xmax = sep * ceil (xmax / scl / sep); | |
169 nticks = (xmax - xmin) / sep + 1; | |
170 xmin *= scl; | |
171 xmax *= scl; | |
172 else | |
173 [ymin, mmin, dmin] = datevec (xmin); | |
174 [ymax, mmax, dmax] = datevec (xmax); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
175 minyear = ymin + (mmin - 1) / 12 + (dmin - 1) / 12 / 30; |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
176 maxyear = ymax + (mmax - 1) / 12 + (dmax - 1) / 12 / 30; |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
177 minmonth = mmin + (dmin - 1) / 30; |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
178 maxmonth = (ymax - ymin) * 12 + mmax + (dmax - 1) / 30; |
8112 | 179 |
180 if (maxmonth - minmonth < N) | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
181 sep = __calc_tick_sep__ (xmin, xmax); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
182 xmin = sep * floor (xmin / sep); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
183 xmax = sep * ceil (xmax / sep); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
184 nticks = (xmax - xmin) / sep + 1; |
8112 | 185 elseif (maxyear - minyear < N) |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
186 sep = __calc_tick_sep__ (minmonth , maxmonth); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
187 xmin = datenum (ymin, sep * floor (minmonth / sep), 1); |
14665
4f458e882516
Allow fractional months to datenum and correct a couple of typos in datetick (bug #36482)
David Bateman <dbateman@free.fr>
parents:
14552
diff
changeset
|
188 xmax = datenum (ymax, sep * ceil (maxmonth / sep), 1); |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
189 nticks = ceil (maxmonth / sep) - floor (minmonth / sep) + 1; |
8112 | 190 else |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
191 sep = __calc_tick_sep__ (minyear , maxyear); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
192 xmin = datenum (sep * floor (minyear / sep), 1, 1); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
193 xmax = datenum (sep * ceil (maxyear / sep), 1, 1); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
194 nticks = ceil (maxyear / sep) - floor (minyear / sep) + 1; |
8112 | 195 endif |
196 endif | |
197 ticks = xmin + [0 : nticks - 1] / (nticks - 1) * (xmax - xmin); | |
198 endif | |
199 | |
200 if (isempty (form)) | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
201 r = max (ticks) - min (ticks); |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
202 if (r < 10/60/24) |
8112 | 203 ## minutes and seconds |
204 form = 13; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
205 elseif (r < 2) |
8112 | 206 ## hours |
207 form = 15; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
208 elseif (r < 15) |
8112 | 209 ## days |
210 form = 8; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
211 elseif (r < 365) |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
212 ## FIXME -- FORM should be 19 for European users who use dd/mm |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
213 ## instead of mm/dd. How can that be determined automatically? |
8112 | 214 ## months |
215 form = 6; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
216 elseif (r < 90*12) |
8112 | 217 ## quarters |
218 form = 27; | |
219 else | |
220 ## years | |
221 form = 10; | |
222 endif | |
223 endif | |
224 | |
225 if (length (ticks) == 6) | |
226 ## Careful that its not treated as a datevec | |
227 if (! isempty (startdate)) | |
228 sticks = strvcat (datestr (ticks(1:end-1) - ticks(1) + startdate, form), | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
229 datestr (ticks(end) - ticks(1) + startdate, form)); |
8112 | 230 else |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
231 sticks = strvcat (datestr (ticks(1:end-1), form), |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
232 datestr (ticks(end), form)); |
8112 | 233 endif |
234 else | |
235 if (! isempty (startdate)) | |
236 sticks = datestr (ticks - ticks(1) + startdate, form); | |
237 else | |
238 sticks = datestr (ticks, form); | |
239 endif | |
240 endif | |
241 | |
242 sticks = mat2cell (sticks, ones (rows (sticks), 1), columns (sticks)); | |
243 | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
244 if (keepticks) |
8112 | 245 if (keeplimits) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14665
diff
changeset
|
246 set (gca (), strcat (ax, "ticklabel"), sticks); |
8112 | 247 else |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14665
diff
changeset
|
248 set (gca (), strcat (ax, "ticklabel"), sticks, strcat (ax, "lim"), |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
249 [min(ticks), max(ticks)]); |
8112 | 250 endif |
251 else | |
252 if (keeplimits) | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14665
diff
changeset
|
253 set (gca (), strcat (ax, "tick"), ticks, strcat (ax, "ticklabel"), sticks); |
8112 | 254 else |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14665
diff
changeset
|
255 set (gca (), strcat (ax, "tick"), ticks, strcat (ax, "ticklabel"), sticks, |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
256 strcat (ax, "lim"), [min(ticks), max(ticks)]); |
8112 | 257 endif |
258 endif | |
259 endfunction | |
260 | |
261 function [a, b] = __magform__ (x) | |
262 if (x == 0) | |
263 a = 0; | |
264 b = 0; | |
265 else | |
266 l = log10 (abs (x)); | |
267 r = fmod (l, 1); | |
268 a = 10 .^ r; | |
269 b = fix (l - r); | |
270 if (a < 1) | |
271 a *= 10; | |
272 b -= 1; | |
273 endif | |
274 if (x < 0) | |
275 a = -a; | |
276 endif | |
277 endif | |
278 endfunction | |
279 | |
280 ## A translation from Tom Holoryd's python code at | |
281 ## http://kurage.nimh.nih.gov/tomh/tics.py | |
282 function sep = __calc_tick_sep__ (lo, hi) | |
283 persistent sqrt_2 = sqrt (2.0); | |
284 persistent sqrt_10 = sqrt (10.0); | |
285 persistent sqrt_50 = sqrt (50.0); | |
286 | |
287 ticint = 5; | |
288 | |
289 ## Reference: Lewart, C. R., "Algorithms SCALE1, SCALE2, and | |
290 ## SCALE3 for Determination of Scales on Computer Generated | |
291 ## Plots", Communications of the ACM, 10 (1973), 639-640. | |
292 ## Also cited as ACM Algorithm 463. | |
293 | |
294 [a, b] = __magform__ ((hi - lo) / ticint); | |
295 | |
296 if (a < sqrt_2) | |
297 x = 1; | |
298 elseif (a < sqrt_10) | |
299 x = 2; | |
300 elseif (a < sqrt_50) | |
301 x = 5; | |
302 else | |
303 x = 10; | |
304 endif | |
305 sep = x * 10 .^ b; | |
306 endfunction | |
307 |