Mercurial > octave
annotate scripts/plot/appearance/datetick.m @ 23219:3ac9f9ecfae5 stable
maint: Update copyright dates.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 22 Feb 2017 12:39:29 -0500 |
parents | e9a0469dedd9 |
children | 092078913d54 6cbf5c2d4d55 |
rev | line source |
---|---|
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
1 ## Copyright (C) 2008-2017 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 -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
20 ## @deftypefn {} {} datetick () |
22161
9babcd597676
Visual differences between Octave and Matlab (bug #48572)
Markus Mützel <markus.muetzel@gmx.de>
parents:
22151
diff
changeset
|
21 ## @deftypefnx {} {} datetick (@var{date_format}) |
9babcd597676
Visual differences between Octave and Matlab (bug #48572)
Markus Mützel <markus.muetzel@gmx.de>
parents:
22151
diff
changeset
|
22 ## @deftypefnx {} {} datetick (@var{axis_str}, @var{date_format}) |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
23 ## @deftypefnx {} {} datetick (@dots{}, "keeplimits") |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
24 ## @deftypefnx {} {} datetick (@dots{}, "keepticks") |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
25 ## @deftypefnx {} {} datetick (@var{hax}, @dots{}) |
20173
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
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:
19697
diff
changeset
|
27 ## |
22161
9babcd597676
Visual differences between Octave and Matlab (bug #48572)
Markus Mützel <markus.muetzel@gmx.de>
parents:
22151
diff
changeset
|
28 ## The axis to apply the ticks to is determined by @var{axis_str} which can |
9babcd597676
Visual differences between Octave and Matlab (bug #48572)
Markus Mützel <markus.muetzel@gmx.de>
parents:
22151
diff
changeset
|
29 ## take the values @qcode{"x"}, @qcode{"y"}, or @qcode{"z"}. The default |
9babcd597676
Visual differences between Octave and Matlab (bug #48572)
Markus Mützel <markus.muetzel@gmx.de>
parents:
22151
diff
changeset
|
30 ## value is @qcode{"x"}. |
20173
777f26aa8e3e
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
31 ## |
22161
9babcd597676
Visual differences between Octave and Matlab (bug #48572)
Markus Mützel <markus.muetzel@gmx.de>
parents:
22151
diff
changeset
|
32 ## The formatting of the labels is determined by the variable |
9babcd597676
Visual differences between Octave and Matlab (bug #48572)
Markus Mützel <markus.muetzel@gmx.de>
parents:
22151
diff
changeset
|
33 ## @var{date_format}, which can either be a string or positive integer that |
9babcd597676
Visual differences between Octave and Matlab (bug #48572)
Markus Mützel <markus.muetzel@gmx.de>
parents:
22151
diff
changeset
|
34 ## @code{datestr} accepts. |
9babcd597676
Visual differences between Octave and Matlab (bug #48572)
Markus Mützel <markus.muetzel@gmx.de>
parents:
22151
diff
changeset
|
35 ## |
8112 | 36 ## @seealso{datenum, datestr} |
37 ## @end deftypefn | |
38 | |
39 function datetick (varargin) | |
40 | |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
41 [hax, varargin, nargin] = __plt_get_axis_arg__ ("datetick", varargin{:}); |
8112 | 42 |
17211
87ba70043bfc
Don't use ifelse in plot fcns to avoid unnecessary fcn evaluations.
Rik <rik@octave.org>
parents:
17210
diff
changeset
|
43 oldfig = []; |
17301
68bcac3c043a
Correct inversion accidentally introduced in cset 87ba70043bfc.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
44 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
|
45 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
|
46 endif |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
47 if (isempty (hax)) |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
48 hax = gca (); |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
49 endif |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
50 |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
51 unwind_protect |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
52 ## FIXME: This will bring the axes to the top of the stack. |
18348
052cc933aea6
datetick.m: Add more detail to FIXME note.
Rik <rik@octave.org>
parents:
17745
diff
changeset
|
53 ## 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
|
54 ## such as can occur with plotyy. |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
55 axes (hax); |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
56 __datetick__ (varargin{:}); |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
57 unwind_protect_cleanup |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
58 if (! isempty (oldfig)) |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
59 set (0, "currentfigure", oldfig); |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
60 endif |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
61 end_unwind_protect |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
62 |
8112 | 63 endfunction |
64 | |
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 |
8112 | 66 %!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
|
67 %! clf; |
8112 | 68 %! yr = 1900:10:2000; |
69 %! pop = [76.094, 92.407, 106.461, 123.077 131.954, 151.868, 179.979, ... | |
70 %! 203.984, 227.225, 249.623, 282.224]; | |
71 %! plot (datenum (yr, 1, 1), pop); | |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22161
diff
changeset
|
72 %! xlabel ("Year"); |
22312
533c3c4059a3
Add titles to more of the graphic demos.
Rik <rik@octave.org>
parents:
22302
diff
changeset
|
73 %! ylabel ("US population (millions)"); |
533c3c4059a3
Add titles to more of the graphic demos.
Rik <rik@octave.org>
parents:
22302
diff
changeset
|
74 %! title ("datetick() with 4-digit year format"); |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22161
diff
changeset
|
75 %! datetick ("x", "YYYY"); |
8112 | 76 |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
77 %!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
|
78 %! clf; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
79 %! 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
|
80 %! yr = datenum (yr,1,1); |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
81 %! pr = [12.1 13.3 12.6 13.1 13.3 14.1 14.4 15.2]; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22161
diff
changeset
|
82 %! plot (yr, pr, "-o"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22161
diff
changeset
|
83 %! xlabel ("year"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22161
diff
changeset
|
84 %! ylabel ("average price"); |
22312
533c3c4059a3
Add titles to more of the graphic demos.
Rik <rik@octave.org>
parents:
22302
diff
changeset
|
85 %! title ("datetick() with MM/DD/YY format"); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
86 %! ax = gca; |
22302
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22161
diff
changeset
|
87 %! set (ax, "xtick", datenum (1990:5:2005,1,1)); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22161
diff
changeset
|
88 %! datetick ("x", 2, "keepticks"); |
1c4cd12987f5
Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents:
22161
diff
changeset
|
89 %! set (ax, "ytick", 12:16); |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
90 |
13082
35c0b722d2e4
codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
91 ## Remove from test statistics. No real tests possible. |
35c0b722d2e4
codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
92 %!assert (1) |
35c0b722d2e4
codesprint: mark datetick as tested.
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
93 |
8112 | 94 function __datetick__ (varargin) |
95 | |
96 keeplimits = false; | |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
97 idx = strcmpi (varargin, "keeplimits"); |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
98 if (any (idx)) |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
99 keeplimits = true; |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
100 varargin = varargin(! idx); |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
101 endif |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
102 keepticks = false; |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
103 idx = strcmpi (varargin, "keepticks"); |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
104 if (any (idx)) |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
105 keepticks = true; |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
106 varargin = varargin(! idx); |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
107 endif |
8112 | 108 |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
109 nargin = numel (varargin); |
8112 | 110 form = []; |
111 ax = "x"; | |
112 | |
113 if (nargin != 0) | |
114 arg = varargin{1}; | |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
115 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
|
116 ax = tolower (arg); |
8112 | 117 if (nargin > 1) |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
118 form = varargin{2}; |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
119 varargin(1:2) = []; |
8112 | 120 else |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
121 varargin(1) = []; |
8112 | 122 endif |
123 else | |
124 form = arg; | |
125 varargin(1) = []; | |
126 endif | |
127 endif | |
128 | |
129 ## Don't publish the existence of this variable for use with dateaxis | |
130 if (length (varargin) > 0) | |
131 startdate = varargin{1}; | |
132 else | |
133 startdate = []; | |
134 endif | |
135 | |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
136 if (! isempty (form)) |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
137 if (isnumeric (form)) |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
138 if (! isscalar (form) || form < 0 || form != fix (form)) |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20173
diff
changeset
|
139 error ("datetick: FORM argument must be a positive integer"); |
10151
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
140 endif |
c2f1cdb59821
datetick: make form argument optional
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
141 elseif (! ischar (form)) |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20173
diff
changeset
|
142 error ("datetick: FORM argument must be a valid date format string"); |
8112 | 143 endif |
144 endif | |
145 | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
146 if (keepticks) |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
147 ticks = get (gca (), [ax "tick"]); |
8112 | 148 else |
149 ## Need to do our own axis tick position calculation as | |
21167
7705a858262b
datetick.m: Use Octave coding conventions in cset (446bab5da2f7).
Rik <rik@octave.org>
parents:
21165
diff
changeset
|
150 ## year, etc., don't fall back to nice datenum values. |
21165
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
151 if (keeplimits) |
21167
7705a858262b
datetick.m: Use Octave coding conventions in cset (446bab5da2f7).
Rik <rik@octave.org>
parents:
21165
diff
changeset
|
152 limits = get (gca (), [ax "lim"]); |
7705a858262b
datetick.m: Use Octave coding conventions in cset (446bab5da2f7).
Rik <rik@octave.org>
parents:
21165
diff
changeset
|
153 xmin = limits(1); |
21174
a223cce1daa4
strip trailing space from source files we maintain
John W. Eaton <jwe@octave.org>
parents:
21167
diff
changeset
|
154 xmax = limits(2); |
21165
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
155 else |
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
156 objs = findall (gca ()); |
21167
7705a858262b
datetick.m: Use Octave coding conventions in cset (446bab5da2f7).
Rik <rik@octave.org>
parents:
21165
diff
changeset
|
157 xmin = xmax = NaN; |
7705a858262b
datetick.m: Use Octave coding conventions in cset (446bab5da2f7).
Rik <rik@octave.org>
parents:
21165
diff
changeset
|
158 for i = 1 : numel (objs) |
7705a858262b
datetick.m: Use Octave coding conventions in cset (446bab5da2f7).
Rik <rik@octave.org>
parents:
21165
diff
changeset
|
159 fld = get (objs(i)); |
21165
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
160 if (isfield (fld, [ax "data"])) |
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
161 xdata = getfield (fld, [ax "data"])(:); |
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
162 xmin = min (xmin, min (xdata)); |
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
163 xmax = max (xmax, max (xdata)); |
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
164 endif |
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
165 endfor |
446bab5da2f7
datetick.m: properly process keeplimits (bug #46484)
Lars Kindermann
parents:
20852
diff
changeset
|
166 endif |
8112 | 167 |
168 if (isnan (xmin) || isnan (xmax)) | |
169 xmin = 0; | |
170 xmax = 1; | |
171 elseif (xmin == xmax) | |
172 xmax = xmin + 1; | |
173 endif | |
174 | |
175 N = 3; | |
176 if (xmax - xmin < N) | |
177 ## Day scale or less | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
178 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
|
179 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
|
180 elseif (xmax - xmin < N / 24 / 60) |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
181 scl = 1 / 24 / 60; |
8112 | 182 else |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
183 scl = 1 / 24; |
8112 | 184 endif |
185 sep = __calc_tick_sep__ (xmin / scl , xmax / scl); | |
186 xmin = sep * floor (xmin / scl / sep); | |
187 xmax = sep * ceil (xmax / scl / sep); | |
188 nticks = (xmax - xmin) / sep + 1; | |
189 xmin *= scl; | |
190 xmax *= scl; | |
22752
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
191 ticks = xmin + [0 : nticks - 1] / (nticks - 1) * (xmax - xmin); |
8112 | 192 else |
193 [ymin, mmin, dmin] = datevec (xmin); | |
194 [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
|
195 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
|
196 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
|
197 minmonth = mmin + (dmin - 1) / 30; |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
198 maxmonth = (ymax - ymin) * 12 + mmax + (dmax - 1) / 30; |
8112 | 199 |
200 if (maxmonth - minmonth < N) | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
201 sep = __calc_tick_sep__ (xmin, xmax); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
202 xmin = sep * floor (xmin / sep); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
203 xmax = sep * ceil (xmax / sep); |
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
204 nticks = (xmax - xmin) / sep + 1; |
22752
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
205 ticks = xmin + [0 : nticks - 1] / (nticks - 1) * (xmax - xmin); |
8112 | 206 elseif (maxyear - minyear < N) |
22752
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
207 sep = __calc_tick_sep__ (minmonth, maxmonth); |
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
208 minyear = floor (minyear); |
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
209 minmonth = sep * floor (minmonth / sep); |
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
210 minmonth = ifelse (minmonth == 0, 1, minmonth); |
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
211 maxmonth = sep * ceil (maxmonth / sep); |
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
212 rangemonth = (minmonth:sep:maxmonth)'; |
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
213 ticks = datenum ([repmat(minyear, size(rangemonth)), ... |
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
214 rangemonth, ... |
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
215 ones(size (rangemonth))]); |
8112 | 216 else |
22752
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
217 sep = __calc_tick_sep__ (minyear, maxyear); |
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
218 minyear = sep * floor (minyear / sep); |
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
219 maxyear = sep * ceil (maxyear / sep); |
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
220 rangeyear = (minyear:sep:maxyear)'; |
ee34028f63fc
datetick.m: Fix unequal spacing of months and years (bug #39727).
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
221 ticks = datenum ([rangeyear, ones(rows(rangeyear),2)]); |
8112 | 222 endif |
223 endif | |
224 endif | |
225 | |
226 if (isempty (form)) | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
227 r = max (ticks) - min (ticks); |
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
228 if (r < 10/60/24) |
8112 | 229 ## minutes and seconds |
230 form = 13; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
231 elseif (r < 2) |
8112 | 232 ## hours |
233 form = 15; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
234 elseif (r < 15) |
8112 | 235 ## days |
236 form = 8; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
237 elseif (r < 365) |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
238 ## 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
|
239 ## instead of mm/dd. How can that be determined automatically? |
8112 | 240 ## months |
241 form = 6; | |
14552
86854d032a37
maint: miscellaneous style fixes for .m files
John W. Eaton <jwe@octave.org>
parents:
14363
diff
changeset
|
242 elseif (r < 90*12) |
8112 | 243 ## quarters |
244 form = 27; | |
245 else | |
246 ## years | |
247 form = 10; | |
248 endif | |
249 endif | |
250 | |
251 if (length (ticks) == 6) | |
252 ## Careful that its not treated as a datevec | |
253 if (! isempty (startdate)) | |
254 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
|
255 datestr (ticks(end) - ticks(1) + startdate, form)); |
8112 | 256 else |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
257 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
|
258 datestr (ticks(end), form)); |
8112 | 259 endif |
260 else | |
261 if (! isempty (startdate)) | |
262 sticks = datestr (ticks - ticks(1) + startdate, form); | |
263 else | |
264 sticks = datestr (ticks, form); | |
265 endif | |
266 endif | |
267 | |
268 sticks = mat2cell (sticks, ones (rows (sticks), 1), columns (sticks)); | |
269 | |
10369
3516a245d607
datetick.m: Fix 'keepticks' bug, and untabify.
Ben Abbott <bpabbott@mac.com>
parents:
10151
diff
changeset
|
270 if (keepticks) |
8112 | 271 if (keeplimits) |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
272 set (gca (), [ax "ticklabel"], sticks); |
8112 | 273 else |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
274 set (gca (), [ax "ticklabel"], sticks, |
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
275 [ax "lim"], [min(ticks), max(ticks)]); |
8112 | 276 endif |
277 else | |
278 if (keeplimits) | |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
279 set (gca (), [ax "tick"], ticks, [ax "ticklabel"], sticks); |
8112 | 280 else |
17210
73dd413f2c3e
datetick.m: Use modern coding conventions in function.
Rik <rik@octave.org>
parents:
16094
diff
changeset
|
281 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
|
282 [ax "lim"], [min(ticks), max(ticks)]); |
8112 | 283 endif |
284 endif | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21174
diff
changeset
|
285 |
8112 | 286 endfunction |
287 | |
288 function [a, b] = __magform__ (x) | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21174
diff
changeset
|
289 |
8112 | 290 if (x == 0) |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21174
diff
changeset
|
291 a = b = 0; |
8112 | 292 else |
293 l = log10 (abs (x)); | |
19118 | 294 r = rem (l, 1); |
8112 | 295 a = 10 .^ r; |
296 b = fix (l - r); | |
297 if (a < 1) | |
298 a *= 10; | |
299 b -= 1; | |
300 endif | |
301 if (x < 0) | |
302 a = -a; | |
303 endif | |
304 endif | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21174
diff
changeset
|
305 |
8112 | 306 endfunction |
307 | |
308 ## A translation from Tom Holoryd's python code at | |
309 ## http://kurage.nimh.nih.gov/tomh/tics.py | |
310 function sep = __calc_tick_sep__ (lo, hi) | |
311 persistent sqrt_2 = sqrt (2.0); | |
312 persistent sqrt_10 = sqrt (10.0); | |
313 persistent sqrt_50 = sqrt (50.0); | |
314 | |
315 ticint = 5; | |
316 | |
317 ## Reference: Lewart, C. R., "Algorithms SCALE1, SCALE2, and | |
318 ## SCALE3 for Determination of Scales on Computer Generated | |
319 ## Plots", Communications of the ACM, 10 (1973), 639-640. | |
320 ## Also cited as ACM Algorithm 463. | |
321 | |
322 [a, b] = __magform__ ((hi - lo) / ticint); | |
323 | |
324 if (a < sqrt_2) | |
325 x = 1; | |
326 elseif (a < sqrt_10) | |
327 x = 2; | |
328 elseif (a < sqrt_50) | |
329 x = 5; | |
330 else | |
331 x = 10; | |
332 endif | |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21174
diff
changeset
|
333 |
8112 | 334 sep = x * 10 .^ b; |
21758
ffad2baa90f7
maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents:
21174
diff
changeset
|
335 |
8112 | 336 endfunction |