]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/caxis.m
update packages
[CreaPhase.git] / octave_packages / m / plot / caxis.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} {} caxis (@var{limits})
21 ## @deftypefnx {Function File} {} caxis (@var{h}, @dots{})
22 ## Set color axis limits for plots.
23 ##
24 ## The argument @var{limits} should be a 2-element vector specifying the
25 ## lower and upper limits to assign to the first and last value in the
26 ## colormap.  Values outside this range are clamped to the first and last
27 ## colormap entries.
28 ##
29 ## If @var{limits} is 'auto', then automatic colormap scaling is applied,
30 ## whereas if @var{limits} is 'manual' the colormap scaling is set to manual.
31 ##
32 ## Called without any arguments to current color axis limits are returned.
33 ##
34 ## If an axes handle is passed as the first argument, then operate on
35 ## this axes rather than the current axes.
36 ## @end deftypefn
37
38 function varargout = caxis (varargin)
39
40   [h, varargin, nargin] = __plt_get_axis_arg__ ("caxis", varargin{:});
41
42   oldh = gca ();
43   unwind_protect
44     axes (h);
45     varargout = cell (max (nargin == 0, nargout), 1);
46     if (isempty (varargout))
47       __caxis__ (h, varargin{:});
48     else
49       [varargout{:}] = __caxis__ (h, varargin{:});
50     endif
51   unwind_protect_cleanup
52     axes (oldh);
53   end_unwind_protect
54
55 endfunction
56
57 function [cmin, cmax] = __caxis__ (ca, ax, varargin)
58
59   if (nargin == 1)
60     cmin = get (ca, "clim");
61     if (nargout > 1)
62       cmax = cmin(2);
63       cmin = cmin(1);
64     endif
65   elseif (ischar (ax))
66     if (strcmpi (ax, "auto"))
67       set (ca, "climmode", "auto");
68     elseif (strcmpi (ax, "manual"))
69       set (ca, "climmode", "manual");
70     endif
71   elseif (isvector (ax))
72     len = length (ax);
73
74     if (len != 2)
75       error ("caxis: expecting vector with 2 elements");
76     endif
77
78     set (ca, "clim", [ax(1), ax(2)]);
79   else
80     error ("caxis: expecting no args, a string or a 2 element vector");
81   endif
82
83   if (nargin > 2)
84     __caxis__ (ca, varargin{:})';
85   endif
86
87 endfunction
88