3431
|
1 ## Copyright (C) 1998 Auburn University. All rights reserved. |
|
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 the |
|
7 ## Free Software Foundation; either version 2, or (at your option) any |
|
8 ## later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 ## 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, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301 USA. |
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 if(delv(1) != 0) |
|
65 axdel(1:2) = 1.1*[-delv(1),delv(1)]; |
|
66 endif |
6518
|
67 if(abs(delv(2)) >= tolv(2)) |
3431
|
68 axdel(3:4) = 1.1*[-delv(2),delv(2)]; |
|
69 endif |
|
70 endif |
|
71 axvec = axmid + axdel; |
|
72 endfunction |
|
73 |