]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/pbaspect.m
update packages
[CreaPhase.git] / octave_packages / m / plot / pbaspect.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} {} 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.
24 ##
25 ## @deftypefnx {Function File} {@var{plot_box_aspect_ratio} =} pbaspect ( )
26 ## Return the plot box aspect ratio of the current axes.
27 ##
28 ## @deftypefnx {Function File} {} pbaspect (@var{mode})
29 ## Set the plot box aspect ratio mode of the current axes.
30 ##
31 ## @deftypefnx {Function File} {@var{plot_box_aspect_ratio_mode} =} pbaspect ("mode")
32 ## Return the plot box aspect ratio mode of the current axes.
33 ##
34 ## @deftypefnx {Function File} {} pbaspect (@var{hax}, @dots{})
35 ## Use the axes, with handle @var{hax}, instead of the current axes.
36 ##
37 ## @seealso{axis, daspect, xlim, ylim, zlim}
38 ## @end deftypefn
39
40 ## Author: Ben Abbott <bpabbott@mac.com>
41 ## Created: 2010-01-26
42
43 function varargout = pbaspect (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, "plotboxaspectratiomode");
61             return
62           else
63             error ("pbaspect: only one output is allowed");
64           endif
65         case "manual"
66           set (hax, "plotboxaspectratiomode", "manual");
67         case "auto"
68           set (hax, "plotboxaspectratiomode", "auto");
69         endswitch
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});
74       else
75         error ("pbaspect: invalid input");
76       endif
77     elseif (numel (varargin) > 1)
78       error ("pbaspect: too many inputs");
79     endif
80   elseif (nargout == 0)
81     print_usage ();
82   endif
83
84   if (nargout == 1)
85     varargout{1} = get (hax, "plotboxaspectratio");
86   elseif (nargout > 1)
87     error ("pbaspect: 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 %! pbaspect ([1 1 1])
97 %! title ("plot box should be square")
98
99 %!demo
100 %! x = 0:0.01:4;
101 %! clf
102 %! plot (x, cos (x), x, sin (x))
103 %! pbaspect ([2 1 1])
104 %! title ("plot box aspect ratio should be 2x1")
105
106 %!demo
107 %! x = 0:0.01:4;
108 %! clf
109 %! plot (x, cos (x), x, sin (x))
110 %! daspect ([1 1 1])
111 %! pbaspect ([2 1 1])
112 %! title ("plot box should be 2x1, and axes [0 4 -1 1]")
113