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