7189
|
1 ## Copyright (C) 2007 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 ## PKG_ADD: mark_as_command caxis |
|
39 |
|
40 function varargout = caxis (varargin) |
|
41 |
7215
|
42 [h, varargin, nargin] = __plt_get_axis_arg__ ("caxis", varargin{:}); |
7216
|
43 |
7215
|
44 oldh = gca (); |
|
45 unwind_protect |
|
46 axes (h); |
7189
|
47 varargout = cell (max (nargin == 0, nargout), 1); |
|
48 if (isempty (varargout)) |
7215
|
49 __caxis__ (h, varargin{:}); |
7189
|
50 else |
7215
|
51 [varargout{:}] = __caxis__ (h, varargin{:}); |
7189
|
52 endif |
7215
|
53 unwind_protect_cleanup |
|
54 axes (oldh); |
|
55 end_unwind_protect |
7189
|
56 |
|
57 endfunction |
|
58 |
|
59 function [cmin, cmax] = __caxis__ (ca, ax, varargin) |
|
60 |
|
61 if (nargin == 1) |
|
62 cmin = get (ca, "clim"); |
|
63 if (nargout > 1) |
|
64 cmax = cmin(2); |
|
65 cmin = cmin(1); |
|
66 endif |
|
67 elseif (ischar (ax)) |
|
68 ax = tolower (ax); |
|
69 if (strcmp (ax, "auto")) |
|
70 set (ca, "climmode", "auto"); |
|
71 elseif (strcmp (ax, "manual")) |
|
72 set (ca, "climmode", "manual"); |
|
73 endif |
|
74 elseif (isvector (ax)) |
|
75 len = length (ax); |
|
76 |
|
77 if (len != 2) |
|
78 error ("caxis: expecting vector with 2 elements"); |
|
79 endif |
|
80 |
|
81 set (ca, "clim", [ax(1), ax(2)]); |
|
82 else |
|
83 error ("caxis: expecting no args, a string or a 2 element vector"); |
|
84 endif |
|
85 |
|
86 if (nargin > 2) |
|
87 __caxis__ (ca, varargin{:})' |
|
88 endif |
|
89 |
|
90 endfunction |
|
91 |