Mercurial > hg > octave-nkf
annotate scripts/plot/appearance/datetick.m @ 20787:40ed9b46a800
new octave_value::string_value method with optional error message
* ov.h (octave_value::string_vector): New method.
ov-base.cc, ov-base.h (octave_base_value::string_vector):
New default method.
ov-str-mat.cc, ov-str-mat.h (octave_char_matrix_str::string_value):
New method.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 08 Oct 2015 16:43:22 -0400 |
parents | 777f26aa8e3e |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
1 ## Copyright (C) 2008-2015 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{}) |
20383
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
26 ## Add date formatted tick labels to an axis. |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
27 ## |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
28 ## The axis to apply the ticks to is determined by @var{axis} which can take |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
29 ## the values @qcode{"x"}, @qcode{"y"}, or @qcode{"z"}. The default value is |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
30 ## @qcode{"x"}. |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
31 ## |
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
32 ## The formatting of the labels is determined by the variable @var{form}, which |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17211
diff
changeset
|
33 ## can either be a string or positive integer that @code{datestr} accepts. |
8112 | 34 ## @seealso{datenum, datestr} |
35 ## @end deftypefn | |
36 | |
37 function datetick (varargin) | |
38 | |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
39 [hax, varargin, nargin] = __plt_get_axis_arg__ ("datetick", varargin{:}); |
8112 | 40 |
17211
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17210
diff
changeset
|
41 oldfig = []; |
17301
68bcac3c043a
Correct inversion accidentally introduced in cset 87ba70043bfc.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
42 if (! isempty (hax)) |
17211
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17210
diff
changeset
|
43 oldfig = get (0, "currentfigure"); |
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17210
diff
changeset
|
44 endif |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
45 if (isempty (hax)) |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
46 hax = gca (); |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
47 endif |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
48 |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
49 unwind_protect |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
50 ## FIXME: This will bring the axes to the top of the stack. |
18416
052cc933aea6
datetick.m: Add more detail to FIXME note.
Rik <rik@octave.org>
parents:
17745
diff
changeset
|
51 ## This may not be desirable if there are multiple axes objects, |
052cc933aea6
datetick.m: Add more detail to FIXME note.
Rik <rik@octave.org>
parents:
17745
diff
changeset
|
52 ## such as can occur with plotyy. |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
53 axes (hax); |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
54 __datetick__ (varargin{:}); |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
55 unwind_protect_cleanup |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
56 if (! isempty (oldfig)) |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
57 set (0, "currentfigure", oldfig); |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
58 endif |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
59 end_unwind_protect |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
60 |
8112 | 61 endfunction |
62 | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
63 |
8112 | 64 %!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
|
65 %! clf; |
8112 | 66 %! yr = 1900:10:2000; |
67 %! pop = [76.094, 92.407, 106.461, 123.077 131.954, 151.868, 179.979, ... | |
68 %! 203.984, 227.225, 249.623, 282.224]; | |
69 %! plot (datenum (yr, 1, 1), pop); | |
19066
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18416
diff
changeset
|
70 %! title ('US population (millions)'); |
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18416
diff
changeset
|
71 %! xlabel ('Year'); |
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18416
diff
changeset
|
72 %! datetick ('x', 'YYYY'); |
8112 | 73 |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
74 %!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
|
75 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
76 %! 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
|
77 %! yr = datenum (yr,1,1); |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
78 %! pr = [12.1 13.3 12.6 13.1 13.3 14.1 14.4 15.2]; |
19066
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18416
diff
changeset
|
79 %! plot (yr, pr, '-o'); |
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18416
diff
changeset
|
80 %! xlabel ('year'); |
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18416
diff
changeset
|
81 %! ylabel ('average price'); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
82 %! ax = gca; |
19066
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18416
diff
changeset
|
83 %! set (ax, 'xtick', datenum (1990:5:2005,1,1)); |
19114
9a5e03801d23
Update some plot %!demos so that they run under Matlab.
Rik <rik@octave.org>
parents:
19066
diff
changeset
|
84 %! datetick (2, 'x', 'keepticks'); |
19066
cafffc1b70b1
update plot demo blocks for compare_plot_demos
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18416
diff
changeset
|
85 %! set (ax, 'ytick', 12:16); |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
86 |
13082
35c0b722d2e4
codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
87 ## Remove from test statistics. No real tests possible. |
35c0b722d2e4
codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
88 %!assert (1) |
35c0b722d2e4
codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
89 |
8112 | 90 function __datetick__ (varargin) |
91 | |
92 keeplimits = false; | |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
93 idx = strcmpi (varargin, "keeplimits"); |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
94 if (any (idx)) |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
95 keeplimits = true; |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
96 varargin = varargin(! idx); |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
97 endif |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
98 keepticks = false; |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
99 idx = strcmpi (varargin, "keepticks"); |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
100 if (any (idx)) |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
101 keepticks = true; |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
102 varargin = varargin(! idx); |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
103 endif |
8112 | 104 |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
105 nargin = numel (varargin); |
8112 | 106 form = []; |
107 ax = "x"; | |
108 | |
109 if (nargin != 0) | |
110 arg = varargin{1}; | |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
111 if (ischar (arg) && any (strcmpi (arg, {"x", "y", "z"}))) |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
112 ax = tolower (arg); |
8112 | 113 if (nargin > 1) |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
114 form = varargin{2}; |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
115 varargin(1:2) = []; |
8112 | 116 else |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
117 varargin(1) = []; |
8112 | 118 endif |
119 else | |
120 form = arg; | |
121 varargin(1) = []; | |
122 endif | |
123 endif | |
124 | |
125 ## Don't publish the existence of this variable for use with dateaxis | |
126 if (length (varargin) > 0) | |
127 startdate = varargin{1}; | |
128 else | |
129 startdate = []; | |
130 endif | |
131 | |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
132 if (! isempty (form)) |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
133 if (isnumeric (form)) |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
134 if (! isscalar (form) || form < 0 || form != fix (form)) |
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
|
135 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
|
136 endif |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
137 elseif (! ischar (form)) |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
138 error ("datetick: expecting valid date format string"); |
8112 | 139 endif |
140 endif | |
141 | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
142 if (keepticks) |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
143 ticks = get (gca (), [ax "tick"]); |
8112 | 144 else |
145 ## Need to do our own axis tick position calculation as | |
146 ## 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
|
147 objs = findall (gca ()); |
8112 | 148 xmax = NaN; |
149 xmin = NaN; | |
150 for i = 1 : length (objs) | |
151 fld = get (objs (i)); | |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
152 if (isfield (fld, [ax "data"])) |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
153 xdata = getfield (fld, [ax "data"])(:); |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
154 xmin = min (xmin, min (xdata)); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
155 xmax = max (xmax, max (xdata)); |
8112 | 156 endif |
157 endfor | |
158 | |
159 if (isnan (xmin) || isnan (xmax)) | |
160 xmin = 0; | |
161 xmax = 1; | |
162 elseif (xmin == xmax) | |
163 xmax = xmin + 1; | |
164 endif | |
165 | |
166 N = 3; | |
167 if (xmax - xmin < N) | |
168 ## Day scale or less | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
169 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
|
170 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
|
171 elseif (xmax - xmin < N / 24 / 60) |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
172 scl = 1 / 24 / 60; |
8112 | 173 else |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
174 scl = 1 / 24; |
8112 | 175 endif |
176 sep = __calc_tick_sep__ (xmin / scl , xmax / scl); | |
177 xmin = sep * floor (xmin / scl / sep); | |
178 xmax = sep * ceil (xmax / scl / sep); | |
179 nticks = (xmax - xmin) / sep + 1; | |
180 xmin *= scl; | |
181 xmax *= scl; | |
182 else | |
183 [ymin, mmin, dmin] = datevec (xmin); | |
184 [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
|
185 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
|
186 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
|
187 minmonth = mmin + (dmin - 1) / 30; |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
188 maxmonth = (ymax - ymin) * 12 + mmax + (dmax - 1) / 30; |
8112 | 189 |
190 if (maxmonth - minmonth < N) | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
191 sep = __calc_tick_sep__ (xmin, xmax); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
192 xmin = sep * floor (xmin / sep); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
193 xmax = sep * ceil (xmax / sep); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
194 nticks = (xmax - xmin) / sep + 1; |
8112 | 195 elseif (maxyear - minyear < N) |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
196 sep = __calc_tick_sep__ (minmonth , maxmonth); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
197 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
|
198 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
|
199 nticks = ceil (maxmonth / sep) - floor (minmonth / sep) + 1; |
8112 | 200 else |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
201 sep = __calc_tick_sep__ (minyear , maxyear); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
202 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
|
203 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
|
204 nticks = ceil (maxyear / sep) - floor (minyear / sep) + 1; |
8112 | 205 endif |
206 endif | |
207 ticks = xmin + [0 : nticks - 1] / (nticks - 1) * (xmax - xmin); | |
208 endif | |
209 | |
210 if (isempty (form)) | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
211 r = max (ticks) - min (ticks); |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
212 if (r < 10/60/24) |
8112 | 213 ## minutes and seconds |
214 form = 13; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
215 elseif (r < 2) |
8112 | 216 ## hours |
217 form = 15; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
218 elseif (r < 15) |
8112 | 219 ## days |
220 form = 8; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
221 elseif (r < 365) |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
222 ## FIXME: FORM should be 19 for European users who use dd/mm |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
223 ## instead of mm/dd. How can that be determined automatically? |
8112 | 224 ## months |
225 form = 6; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
226 elseif (r < 90*12) |
8112 | 227 ## quarters |
228 form = 27; | |
229 else | |
230 ## years | |
231 form = 10; | |
232 endif | |
233 endif | |
234 | |
235 if (length (ticks) == 6) | |
236 ## Careful that its not treated as a datevec | |
237 if (! isempty (startdate)) | |
238 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
|
239 datestr (ticks(end) - ticks(1) + startdate, form)); |
8112 | 240 else |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
241 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
|
242 datestr (ticks(end), form)); |
8112 | 243 endif |
244 else | |
245 if (! isempty (startdate)) | |
246 sticks = datestr (ticks - ticks(1) + startdate, form); | |
247 else | |
248 sticks = datestr (ticks, form); | |
249 endif | |
250 endif | |
251 | |
252 sticks = mat2cell (sticks, ones (rows (sticks), 1), columns (sticks)); | |
253 | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
254 if (keepticks) |
8112 | 255 if (keeplimits) |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
256 set (gca (), [ax "ticklabel"], sticks); |
8112 | 257 else |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
258 set (gca (), [ax "ticklabel"], sticks, |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
259 [ax "lim"], [min(ticks), max(ticks)]); |
8112 | 260 endif |
261 else | |
262 if (keeplimits) | |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
263 set (gca (), [ax "tick"], ticks, [ax "ticklabel"], sticks); |
8112 | 264 else |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
265 set (gca (), [ax "tick"], ticks, [ax "ticklabel"], sticks, |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
266 [ax "lim"], [min(ticks), max(ticks)]); |
8112 | 267 endif |
268 endif | |
269 endfunction | |
270 | |
271 function [a, b] = __magform__ (x) | |
272 if (x == 0) | |
273 a = 0; | |
274 b = 0; | |
275 else | |
276 l = log10 (abs (x)); | |
19310 | 277 r = rem (l, 1); |
8112 | 278 a = 10 .^ r; |
279 b = fix (l - r); | |
280 if (a < 1) | |
281 a *= 10; | |
282 b -= 1; | |
283 endif | |
284 if (x < 0) | |
285 a = -a; | |
286 endif | |
287 endif | |
288 endfunction | |
289 | |
290 ## A translation from Tom Holoryd's python code at | |
291 ## http://kurage.nimh.nih.gov/tomh/tics.py | |
292 function sep = __calc_tick_sep__ (lo, hi) | |
293 persistent sqrt_2 = sqrt (2.0); | |
294 persistent sqrt_10 = sqrt (10.0); | |
295 persistent sqrt_50 = sqrt (50.0); | |
296 | |
297 ticint = 5; | |
298 | |
299 ## Reference: Lewart, C. R., "Algorithms SCALE1, SCALE2, and | |
300 ## SCALE3 for Determination of Scales on Computer Generated | |
301 ## Plots", Communications of the ACM, 10 (1973), 639-640. | |
302 ## Also cited as ACM Algorithm 463. | |
303 | |
304 [a, b] = __magform__ ((hi - lo) / ticint); | |
305 | |
306 if (a < sqrt_2) | |
307 x = 1; | |
308 elseif (a < sqrt_10) | |
309 x = 2; | |
310 elseif (a < sqrt_50) | |
311 x = 5; | |
312 else | |
313 x = 10; | |
314 endif | |
315 sep = x * 10 .^ b; | |
316 endfunction | |
317 |