7017
|
1 ## Copyright (C) 1998, 2000, 2004, 2005, 2007 |
|
2 ## Auburn University. All rights reserved. |
3431
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3431
|
10 ## |
7016
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
3431
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
3431
|
19 |
|
20 ## -*- texinfo -*- |
5314
|
21 ## @deftypefn {Function File} {} axis2dlim (@var{axdata}) |
5016
|
22 ## Determine axis limits for 2-D data (column vectors); leaves a 10% |
|
23 ## margin around the plots. |
|
24 ## Inserts margins of +/- 0.1 if data is one-dimensional |
|
25 ## (or a single point). |
3431
|
26 ## |
5016
|
27 ## @strong{Input} |
|
28 ## @table @var |
|
29 ## @item axdata |
|
30 ## @var{n} by 2 matrix of data [@var{x}, @var{y}]. |
|
31 ## @end table |
3431
|
32 ## |
5016
|
33 ## @strong{Output} |
|
34 ## @table @var |
|
35 ## @item axvec |
|
36 ## Vector of axis limits appropriate for call to @command{axis} function. |
|
37 ## @end table |
3431
|
38 ## @end deftypefn |
|
39 |
|
40 function axvec = axis2dlim (axdata) |
|
41 |
|
42 if(isempty(axdata)) |
|
43 axdata = 0; |
|
44 endif |
|
45 |
|
46 ## compute axis limits |
|
47 minv = min(axdata); |
|
48 maxv = max(axdata); |
|
49 delv = (maxv-minv)/2; # breadth of the plot |
|
50 midv = (minv + maxv)/2; # midpoint of the plot |
|
51 axmid = [midv(1), midv(1), midv(2), midv(2)]; |
|
52 axdel = [-0.1, 0.1,-0.1,0.1]; # default plot width (if less than 2-d data) |
|
53 if(max(delv) == 0) |
|
54 if(midv(1) != 0) |
|
55 axdel(1:2) = [-0.1*midv(1),0.1*midv(1)]; |
|
56 endif |
|
57 if(midv(2) != 0) |
|
58 axdel(3:4) = [-0.1*midv(2),0.1*midv(2)]; |
|
59 endif |
|
60 else |
|
61 ## they're at least one-dimensional |
6518
|
62 tolv = max(1e-8, 1e-8*abs(midv)); |
|
63 if(abs(delv(1)) >= tolv(1)) |
3431
|
64 axdel(1:2) = 1.1*[-delv(1),delv(1)]; |
|
65 endif |
6518
|
66 if(abs(delv(2)) >= tolv(2)) |
3431
|
67 axdel(3:4) = 1.1*[-delv(2),delv(2)]; |
|
68 endif |
|
69 endif |
|
70 axvec = axmid + axdel; |
|
71 endfunction |
|
72 |