]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/xlim.m
update packages
[CreaPhase.git] / octave_packages / m / plot / xlim.m
1 ## Copyright (C) 2007-2012 David Bateman
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 ## @c List other forms of function in documentation index
21 ## @findex ylim
22 ## @findex zlim
23 ##
24 ## @deftypefn  {Function File} {@var{xl} =} xlim ()
25 ## @deftypefnx {Function File} {} xlim (@var{xl})
26 ## @deftypefnx {Function File} {@var{m} =} xlim ('mode')
27 ## @deftypefnx {Function File} {} xlim (@var{m})
28 ## @deftypefnx {Function File} {} xlim (@var{h}, @dots{})
29 ## Get or set the limits of the x-axis of the current plot.  Called without
30 ## arguments @code{xlim} returns the x-axis limits of the current plot.
31 ## If passed a two element vector @var{xl}, the limits of the x-axis are set
32 ## to this value.
33 ##
34 ## The current mode for calculation of the x-axis can be returned with a
35 ## call @code{xlim ('mode')}, and can be either 'auto' or 'manual'.  The
36 ## current plotting mode can be set by passing either 'auto' or 'manual'
37 ## as the argument.
38 ##
39 ## If passed a handle as the first argument, then operate on this handle
40 ## rather than the current axes handle.
41 ## @seealso{ylim, zlim, set, get, gca}
42 ## @end deftypefn
43
44 function retval = xlim (varargin)
45   ret = __axes_limits__ ("xlim", varargin{:});
46
47   if (! isempty (ret))
48     retval = ret;
49   endif
50 endfunction
51
52 %!demo
53 %! clf ();
54 %! line ();
55 %! xlim ([0.2, 0.8]);
56 %! title ("xlim is [0.2, 0.8]");
57 %! assert (xlim (), [0.2, 0.8]);
58
59 %!demo
60 %! clf ();
61 %! line ();
62 %! xlim ('auto');
63 %! title ("xlim is auto");
64 %! assert (xlim ("mode"), "auto");
65
66 %!demo
67 %! clf ();
68 %! plot3 ([0,1], [0,1], [0,1]);
69 %! xlim ([0.2, 0.8]);
70 %! title ("xlim is [0.2, 0.8]");
71 %! assert (xlim (), [0.2, 0.8]);
72
73 %!demo
74 %! clf ();
75 %! plot3 ([0,1], [0,1], [0,1]);
76 %! xlim ('auto');
77 %! title ("xlim is auto");
78 %! assert (xlim ("mode"), "auto");
79
80
81 %!test
82 %! hf = figure ("visible", "off");
83 %! unwind_protect
84 %!   plot3 ([0,1], [0,1], [0,1]);
85 %!   xlim ([0, 1.1]);
86 %!   assert (get (gca, "xlim"), [0, 1.1], eps);
87 %!   assert (xlim ("mode"), "manual");
88 %! unwind_protect_cleanup
89 %!   close (hf);
90 %! end_unwind_protect
91
92 %!test
93 %! hf = figure ("visible", "off");
94 %! unwind_protect
95 %!   h = plot3 ([0,1.1], [0,1], [0, 1]);
96 %!   assert (get (gca, "xlim"), [0, 1.4], eps);
97 %!   assert (xlim ("mode"), "auto");
98 %! unwind_protect_cleanup
99 %!   close (hf);
100 %! end_unwind_protect