1 ## Copyright (C) 2010-2012 Ben Abbott
3 ## This file is part of Octave.
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.
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.
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/>.
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
25 ## @deftypefnx {Function File} {@var{data_aspect_ratio} =} daspect ( )
26 ## Return the data aspect ratio of the current axes.
28 ## @deftypefnx {Function File} {} daspect (@var{mode})
29 ## Set the data aspect ratio mode of the current axes.
31 ## @deftypefnx {Function File} {@var{data_aspect_ratio_mode} =} daspect ("mode")
32 ## Return the data aspect ratio mode of the current axes.
34 ## @deftypefnx {Function File} {} daspect (@var{hax}, @dots{})
35 ## Use the axes, with handle @var{hax}, instead of the current axes.
37 ## @seealso{axis, pbaspect, xlim, ylim, zlim}
40 ## Author: Ben Abbott <bpabbott@mac.com>
41 ## Created: 2010-01-26
43 function varargout = daspect (varargin)
48 if (isscalar (varargin{1}) && ishandle (varargin{1}))
50 varargin = varargin(2:end);
53 if (numel (varargin) > 0)
54 if (numel (varargin) == 1)
55 if (ischar (varargin{1})
56 && any (strcmpi (varargin{1}, {"mode", "manual", "auto"})))
60 varargout{1} = get (hax, "dataaspectratiomode");
63 error ("daspect: only one output is allowed");
66 set (hax, "dataaspectratiomode", "manual");
68 set (hax, "dataaspectratiomode", "auto");
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});
75 error ("daspect: invalid input");
77 elseif (numel (varargin) > 1)
78 error ("daspect: too many inputs");
85 varargout{1} = get (hax, "dataaspectratio");
87 error ("daspect: only one output is allowed");
95 %! plot (x, cos (x), x, sin (x))
98 %! title ("square plot-box with axis limits [0, 4, -2, 2]")
103 %! plot (x, cos (x), x, sin (x))
106 %! title ("square plot-box with axis limits [0, 4, -1, 1]")
111 %! plot (x, cos (x), x, sin (x))
113 %! pbaspect ([2 1 1])
114 %! title ("2x1 plot box with axis limits [0, 4, -2, 2]")
119 %! plot (x, cos (x), x, sin (x))
121 %! set (gca, "activepositionproperty", "position")
123 %! title ("square plot-box with axis limits [0, 4, -2, 2]")
128 %! plot (x, cos (x), x, sin (x))
130 %! set (gca, "activepositionproperty", "position")
132 %! title ("square plot-box with axis limits [0, 4, -1, 1]")