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} {} colorbar (@var{s}) |
|
21 ## @deftypefnx {Function File} {} colorbar ('peer', @var{h}, @dots{}) |
|
22 ## Adds a colorbar to the current axes. Valid values for @var{s} are |
|
23 ## |
|
24 ## @table @asis |
|
25 ## @item 'EastOutside' |
|
26 ## Place the colorbar outside the plot to the right. This is the default. |
|
27 ## @item 'East' |
|
28 ## Place the colorbar inside the plot to the right. |
|
29 ## @item 'WestOutside' |
|
30 ## Place the colorbar outside the plot to the left. |
|
31 ## @item 'West' |
|
32 ## Place the colorbar inside the plot to the left. |
|
33 ## @item 'NorthOutside' |
|
34 ## Place the colorbar above the plot. |
|
35 ## @item 'North' |
|
36 ## Place the colorbar at the top of the plot. |
|
37 ## @item 'SouthOutside' |
|
38 ## Place the colorbar under the plot. |
|
39 ## @item 'South' |
|
40 ## Place the colorbar at the bottom of the plot. |
|
41 ## @item 'Off', 'None' |
|
42 ## Remove any existing colorbar from the plot. |
|
43 ## @end table |
|
44 ## |
|
45 ## If the argument 'peer' is given, then the following argument is treated a |
|
46 ## the axes handle on which to add the colorbar. |
|
47 ## @end deftypefn |
|
48 |
|
49 |
|
50 ## PKG_ADD: mark_as_command colorbar |
|
51 |
|
52 function colorbar (varargin) |
|
53 |
|
54 if (nargin > 0 && strcmpi(varargin{1}, "peer")) |
|
55 if (nargin > 1) |
|
56 ax = varargin{2}; |
|
57 if (!isscalar (ax) || !ishandle (ax) || |
|
58 strcmp (get (ax, "type"), "axes")) |
|
59 error ("colorbar: expecting an axes handle following 'peer'"); |
|
60 endif |
|
61 else |
|
62 error ("colorbar: misisng axes handle after 'peer'"); |
|
63 endif |
|
64 else |
|
65 ax = gca (); |
|
66 endif |
|
67 |
|
68 pos = "eastoutside"; |
|
69 for i = 1 : length (varargin) |
|
70 arg = varargin {i}; |
|
71 if (length(arg) < 1) |
|
72 pos = "eastoutside"; |
|
73 elseif (ischar (arg)) |
|
74 arg = tolower (arg); |
|
75 if (strcmp (arg, "off") || strcmp (arg, "none")) |
|
76 pos = "none"; |
|
77 elseif (strcmp (arg, "north") || strcmp (arg, "south") || |
|
78 strcmp (arg, "east") || strcmp (arg, "west") || |
|
79 strcmp (arg, "northoutside") || strcmp (arg, "southoutside") || |
|
80 strcmp (arg, "eastoutside") || strcmp (arg, "westoutside")) |
|
81 pos = arg; |
|
82 else |
|
83 error ("colorbar: unrecognized position argument"); |
|
84 endif |
|
85 else |
|
86 error ("colorbar: expecting string arguments"); |
|
87 endif |
|
88 endfor |
|
89 |
|
90 set (ax, "__colorbar__", pos); |
|
91 endfunction |
|
92 |
|
93 |
|
94 %!demo |
|
95 %! hold off; |
|
96 %! close all; |
|
97 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); |
|
98 %! imagesc(x) |
|
99 %! colorbar(); |
|
100 |
|
101 %!demo |
|
102 %! hold off; |
|
103 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); |
|
104 %! imagesc(x) |
|
105 %! colorbar("westoutside"); |
|
106 |
|
107 %!demo |
|
108 %! hold off; |
|
109 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); |
|
110 %! imagesc(x) |
|
111 %! colorbar("northoutside"); |
|
112 |
|
113 %!demo |
|
114 %! hold off; |
|
115 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); |
|
116 %! imagesc(x) |
|
117 %! colorbar("southoutside"); |
|
118 |
|
119 %!demo |
|
120 %! hold off; |
|
121 %! subplot(2,2,1) |
|
122 %! contour(peaks()) |
|
123 %! colorbar("east"); |
|
124 %! subplot(2,2,2) |
|
125 %! contour(peaks()) |
|
126 %! colorbar("west"); |
|
127 %! subplot(2,2,3) |
|
128 %! contour(peaks()) |
|
129 %! colorbar("north"); |
|
130 %! subplot(2,2,4) |
|
131 %! contour(peaks()) |
|
132 %! colorbar("south"); |
|
133 |
|
134 %!demo |
|
135 %! hold off; |
|
136 %! n = 64; x = kron (1:n,ones(n,1)); x = abs(x - x.'); |
|
137 %! subplot(2,2,1) |
|
138 %! imagesc(x) |
|
139 %! colorbar(); |
|
140 %! subplot(2,2,2) |
|
141 %! imagesc(x) |
|
142 %! colorbar("westoutside"); |
|
143 %! subplot(2,2,3) |
|
144 %! imagesc(x) |
|
145 %! colorbar("northoutside"); |
|
146 %! subplot(2,2,4) |
|
147 %! imagesc(x) |
|
148 %! colorbar("southoutside"); |
|
149 |