]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/daspect.m
update packages
[CreaPhase.git] / octave_packages / m / plot / daspect.m
1 ## Copyright (C) 2010-2012 Ben Abbott
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 -*-
20 ## @deftypefn {Function File} {} daspect (@var{data_aspect_ratio})
21 ## Set the data aspect ratio of the current axes.  The aspect ratio is
22 ## a normalized 3-element vector representing the span of the x, y, and
23 ## z-axes limits.
24 ##
25 ## @deftypefnx {Function File} {@var{data_aspect_ratio} =} daspect ( )
26 ## Return the data aspect ratio of the current axes.
27 ##
28 ## @deftypefnx {Function File} {} daspect (@var{mode})
29 ## Set the data aspect ratio mode of the current axes.
30 ##
31 ## @deftypefnx {Function File} {@var{data_aspect_ratio_mode} =} daspect ("mode")
32 ## Return the data aspect ratio mode of the current axes.
33 ##
34 ## @deftypefnx {Function File} {} daspect (@var{hax}, @dots{})
35 ## Use the axes, with handle @var{hax}, instead of the current axes.
36 ##
37 ## @seealso{axis, pbaspect, xlim, ylim, zlim}
38 ## @end deftypefn
39
40 ## Author: Ben Abbott <bpabbott@mac.com>
41 ## Created: 2010-01-26
42
43 function varargout = daspect (varargin)
44
45   hax = gca ();
46
47   if (nargin > 0)
48     if (isscalar (varargin{1}) && ishandle (varargin{1}))
49       hax = varargin{1};
50       varargin = varargin(2:end);
51     endif
52   endif
53   if (numel (varargin) > 0)
54     if (numel (varargin) == 1)
55       if (ischar (varargin{1})
56           && any (strcmpi (varargin{1}, {"mode", "manual", "auto"})))
57         switch (varargin{1})
58         case "mode"
59           if (nargout < 2)
60             varargout{1} = get (hax, "dataaspectratiomode");
61             return
62           else
63             error ("daspect: only one output is allowed");
64           endif
65         case "manual"
66           set (hax, "dataaspectratiomode", "manual");
67         case "auto"
68           set (hax, "dataaspectratiomode", "auto");
69         endswitch
70       elseif (isreal (varargin{1}) && numel (varargin{1}) == 2)
71         set (hax, "dataaspectratio", [varargin{1}, 1]);
72       elseif (isreal (varargin{1}) && numel (varargin{1}) == 3)
73         set (hax, "dataaspectratio", varargin{1});
74       else
75         error ("daspect: invalid input");
76       endif
77     elseif (numel (varargin) > 1)
78       error ("daspect: too many inputs");
79     endif
80   elseif (nargout == 0)
81     print_usage ();
82   endif
83
84   if (nargout == 1)
85     varargout{1} = get (hax, "dataaspectratio");
86   elseif (nargout > 1)
87     error ("daspect: only one output is allowed");
88   endif
89
90 endfunction
91
92 %!demo
93 %! x = 0:0.01:4;
94 %! clf
95 %! plot (x, cos (x), x, sin (x))
96 %! axis square
97 %! daspect ([1 1 1])
98 %! title ("square plot-box with axis limits [0, 4, -2, 2]")
99
100 %!demo
101 %! x = 0:0.01:4;
102 %! clf
103 %! plot (x, cos (x), x, sin (x))
104 %! axis ([0 4 -1 1])
105 %! daspect ([2 1 1])
106 %! title ("square plot-box with axis limits [0, 4, -1, 1]")
107
108 %!demo
109 %! x = 0:0.01:4;
110 %! clf
111 %! plot (x, cos (x), x, sin (x))
112 %! daspect ([1 2 1])
113 %! pbaspect ([2 1 1])
114 %! title ("2x1 plot box with axis limits [0, 4, -2, 2]")
115
116 %!demo
117 %! x = 0:0.01:4;
118 %! clf
119 %! plot (x, cos (x), x, sin (x))
120 %! axis square
121 %! set (gca, "activepositionproperty", "position")
122 %! daspect ([1 1 1])
123 %! title ("square plot-box with axis limits [0, 4, -2, 2]")
124
125 %!demo
126 %! x = 0:0.01:4;
127 %! clf
128 %! plot (x, cos (x), x, sin (x))
129 %! axis ([0 4 -1 1])
130 %! set (gca, "activepositionproperty", "position")
131 %! daspect ([2 1 1])
132 %! title ("square plot-box with axis limits [0, 4, -1, 1]")
133