Mercurial > hg > octave-nkf
comparison scripts/plot/daspect.m @ 10218:ce94aaa71a4f
daspect.m, pbaspect.m: New functions.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Thu, 28 Jan 2010 20:59:31 -0500 |
parents | |
children | fbd7843974fa |
comparison
equal
deleted
inserted
replaced
10217:db7fdd6a1512 | 10218:ce94aaa71a4f |
---|---|
1 ## Copyright (C) 2010 Ben Abbott | |
2 ## | |
3 ## This program is free software; you can redistribute it and/or modify | |
4 ## it under the terms of the GNU General Public License as published by | |
5 ## the Free Software Foundation; either version 2 of the License, or | |
6 ## (at your option) any later version. | |
7 ## | |
8 ## This program is distributed in the hope that it will be useful, | |
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 ## GNU General Public License for more details. | |
12 ## | |
13 ## You should have received a copy of the GNU General Public License | |
14 ## along with Octave; see the file COPYING. If not, see | |
15 ## <http://www.gnu.org/licenses/>. | |
16 | |
17 ## -*- texinfo -*- | |
18 ## @deftypefn {Function File} {} daspect (@var{data_aspect_ratio}) | |
19 ## Set the data aspect ratio of the current axes. The aspect ratio is | |
20 ## a normalized 3 element vector representing the span of the x, y, and | |
21 ## z-axes limits. | |
22 ## @deftypefnx {Function File} {@var{data_aspect_ratio} =} daspect ( ) | |
23 ## Return the data aspect ratio of the current axes. | |
24 ## @deftypefnx {Function File} {} daspect (@var{mode}) | |
25 ## Set the data aspect ratio mode of the current axes. | |
26 ## @deftypefnx {Function File} {@var{data_aspect_ratio_mode} =} daspect ("mode") | |
27 ## Return the data aspect ratio mode of the current axes. | |
28 ## @deftypefnx {Function File} {} daspect (@var{hax}, @dots{}) | |
29 ## Uses the axes, with handle @var{hax}, instead of the current axes. | |
30 ## | |
31 ## @seealso{axis, pbaspect, xlim, ylim, zlim} | |
32 ## @end deftypefn | |
33 | |
34 ## Author: Ben Abbott <bpabbott@mac.com> | |
35 ## Created: 2010-01-26 | |
36 | |
37 function varargout = daspect (varargin) | |
38 | |
39 hax = gca (); | |
40 | |
41 if (nargin > 0) | |
42 if (isscalar (varargin{1}) && ishandle (varargin{1})) | |
43 hax = varargin{1}; | |
44 varargin = varargin(2:end); | |
45 endif | |
46 endif | |
47 if (numel (varargin) > 0) | |
48 if (numel (varargin) == 1) | |
49 if (ischar (varargin{1}) | |
50 && any (strcmpi (varargin{1}, {"mode", "manual", "auto"}))) | |
51 switch varargin{1} | |
52 case {"mode"} | |
53 if (nargout < 2) | |
54 varargout{1} = get (hax, "dataaspectratiomode"); | |
55 return | |
56 else | |
57 error ("daspect: only one output is allowed.") | |
58 end | |
59 case {"manual"} | |
60 set (hax, "dataaspectratiomode", "manual"); | |
61 case {"auto"} | |
62 set (hax, "dataaspectratiomode", "auto"); | |
63 endswitch | |
64 elseif (isreal (varargin{1}) | |
65 && any (numel (varargin{1}) == [2 3])) | |
66 set (hax, "dataaspectratio", varargin{1}) | |
67 else | |
68 error ("daspect: invalid input.") | |
69 endif | |
70 elseif (numel (varargin) > 1) | |
71 error ("daspect: too many inputs.") | |
72 endif | |
73 elseif (nargout == 0) | |
74 print_usage (); | |
75 end | |
76 | |
77 if (nargout == 1) | |
78 varargout{1} = get (hax, "dataaspectratio"); | |
79 elseif (nargout > 1) | |
80 error ("daspect: only one output is allowed.") | |
81 end | |
82 | |
83 endfunction | |
84 | |
85 %!demo | |
86 %! x = 0:0.01:4; | |
87 %! clf | |
88 %! plot (x, cos (x), x, sin (x)) | |
89 %! axis square | |
90 %! daspect ([1 1 1]) | |
91 %! title ("axis limits should be [0, 4, -2, 2]") | |
92 | |
93 %!demo | |
94 %! x = 0:0.01:4; | |
95 %! clf | |
96 %! plot (x, cos (x), x, sin (x)) | |
97 %! axis ([0 4 -1 1]) | |
98 %! daspect ([2 1 1]) | |
99 %! title ("axis box should be square") | |
100 |