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} {} pbaspect (@var{plot_box_aspect_ratio})
21 ## Set the plot box aspect ratio of the current axes. The aspect ratio
22 ## is a normalized 3-element vector representing the rendered lengths of
23 ## the x, y, and z-axes.
25 ## @deftypefnx {Function File} {@var{plot_box_aspect_ratio} =} pbaspect ( )
26 ## Return the plot box aspect ratio of the current axes.
28 ## @deftypefnx {Function File} {} pbaspect (@var{mode})
29 ## Set the plot box aspect ratio mode of the current axes.
31 ## @deftypefnx {Function File} {@var{plot_box_aspect_ratio_mode} =} pbaspect ("mode")
32 ## Return the plot box aspect ratio mode of the current axes.
34 ## @deftypefnx {Function File} {} pbaspect (@var{hax}, @dots{})
35 ## Use the axes, with handle @var{hax}, instead of the current axes.
37 ## @seealso{axis, daspect, xlim, ylim, zlim}
40 ## Author: Ben Abbott <bpabbott@mac.com>
41 ## Created: 2010-01-26
43 function varargout = pbaspect (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, "plotboxaspectratiomode");
63 error ("pbaspect: only one output is allowed");
66 set (hax, "plotboxaspectratiomode", "manual");
68 set (hax, "plotboxaspectratiomode", "auto");
70 elseif (isreal (varargin{1}) && numel (varargin{1}) == 2)
71 set (hax, "plotboxaspectratio", [varargin{1}, 1]);
72 elseif (isreal (varargin{1}) && numel (varargin{1}) == 3)
73 set (hax, "plotboxaspectratio", varargin{1});
75 error ("pbaspect: invalid input");
77 elseif (numel (varargin) > 1)
78 error ("pbaspect: too many inputs");
85 varargout{1} = get (hax, "plotboxaspectratio");
87 error ("pbaspect: only one output is allowed");
95 %! plot (x, cos (x), x, sin (x))
97 %! title ("plot box should be square")
102 %! plot (x, cos (x), x, sin (x))
103 %! pbaspect ([2 1 1])
104 %! title ("plot box aspect ratio should be 2x1")
109 %! plot (x, cos (x), x, sin (x))
111 %! pbaspect ([2 1 1])
112 %! title ("plot box should be 2x1, and axes [0 4 -1 1]")