NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/plots/pcbar.m

Revision 495 (checked in by cbc, 11 years ago)

Initial import of Stark code.

Line 
1         function handle=pcbar(loc,clim,begslot,endslot)
2
3 %  PCBAR Displays a partial color bar (color scale).  Works just
4 %        like COLORBAR, but allows for partial display of the colorbar.
5 %
6 %  PCBAR requires the following arguments:
7 %       clim     - the "restricted" contour limits (min, max
8 %                  of the data) -- important - not the new clims!
9 %       begslot  - the beginning index of the part of the concatenated
10 %                  colormap created (see NEWCLIM)
11 %       endslot  - the last index of the desired part of the concatenated
12 %                  colormap used
13 %       loc (not required) - the location ('horiz' or 'vert') for
14 %                  the colorbar (see COLORBAR)
15 %
16 %  output vars:
17 %       handle - the handle to which the partial colorbar corresponds
18 %
19 % Calls: none
20 %
21 %  See also NEWCLIM, a function to trick matlab into letting you use
22 %    multiple colormaps on the same figure. 
23 %
24 %  Last modified:  7 Oct 1999
25 %  Catherine R. Edwards
26 %  based on original COLORBAR.M created by
27 %   Clay M. Thompson 10-9-92
28 %
29 %
30
31 changeNextPlot = 1;
32
33 if nargin==3
34   endslot=begslot;
35   begslot=clim;
36   clim=loc;
37   loc = 'vert';
38 end
39
40 % Catch colorbar('delete') special case -- must be called by the deleteFcn.
41 if nargin==1 & strcmp(loc,'delete'),
42   ax = gcbo;
43   if strcmp(get(ax,'tag'),'TMW_COLORBAR'), ax=get(ax,'parent'); end
44   ud = get(ax,'userdata');
45   if isfield(ud,'PlotHandle') & ishandle(ud.PlotHandle) & ...
46      isfield(ud,'origPos') & ~isempty(ud.origPos)
47      units = get(ud.PlotHandle,'units');
48      set(ud.PlotHandle,'units','normalized');
49      set(ud.PlotHandle,'position',ud.origPos);
50      set(ud.PlotHandle,'units',units);
51   end
52   if isfield(ud,'DeleteProxy') & ishandle(ud.DeleteProxy)
53     delete(ud.DeleteProxy)
54   end
55   if ~isempty(legend)
56     legend % Update legend
57   end
58   return
59 end
60
61 ax = [];
62 if nargin==1,
63     if ishandle(loc)
64         ax = loc;
65         if ~strcmp(get(ax,'type'),'axes'),
66             error('Requires axes handle.');
67         end
68         units = get(ax,'units'); set(ax,'units','pixels');
69         rect = get(ax,'position'); set(ax,'units',units)
70         if rect(3) > rect(4), loc = 'horiz'; else loc = 'vert'; end
71         changeNextPlot = 0;
72     end
73 end
74
75 % Determine color limits explicitly.  If any axes child is an image
76 % use scale based on size of colormap, otherwise use current CAXIS.
77
78 ch = get(gcda,'children');
79
80   % Treat images and surfaces alike if cdatamapping == 'scaled'
81   t = clim;
82   d = (t(2) - t(1))/(endslot-begslot+1);
83   t = [t(1)+d/2  t(2)-d/2];
84
85 h = gcda;
86
87 if nargin==0,
88     % Search for existing colorbar
89     ch = get(findobj(gcf,'type','image','tag','TMW_COLORBAR'),{'parent'}); ax = [];
90     for i=1:length(ch),
91         ud = get(ch{i},'userdata');
92         d = ud.PlotHandle;
93         if prod(size(d))==1 & isequal(d,h),
94             ax = ch{i};
95             pos = get(ch{i},'Position');
96             if pos(3)<pos(4), loc = 'vert'; else loc = 'horiz'; end
97             changeNextPlot = 0;
98             % Make sure image deletefcn doesn't trigger a colorbar('delete')
99             % for colorbar update
100             set(get(ax,'children'),'deletefcn','')
101             break;
102         end
103     end
104 end
105
106 origNextPlot = get(gcf,'NextPlot');
107 if strcmp(origNextPlot,'replacechildren') | strcmp(origNextPlot,'replace'),
108     set(gcf,'NextPlot','add')
109 end
110
111 if loc(1)=='v', % Append vertical scale to right of current plot
112    
113     if isempty(ax),
114         units = get(h,'units'); set(h,'units','normalized')
115         pos = get(h,'Position');
116         [az,el] = view;
117         stripe = 0.075; edge = 0.02;
118         if all([az,el]==[0 90]), space = 0.05; else space = .1; end
119         set(h,'Position',[pos(1) pos(2) pos(3)*(1-stripe-edge-space) pos(4)])
120         rect = [pos(1)+(1-stripe-edge)*pos(3) pos(2) stripe*pos(3) pos(4)];
121         ud.origPos = pos;
122        
123         % Create axes for stripe and
124         % create DeleteProxy object (an invisible text object in
125         % the target axes) so that the colorbar will be deleted
126         % properly.
127         ud.DeleteProxy = text('parent',h,'visible','off',...
128                               'tag','ColorbarDeleteProxy',...
129                               'handlevisibility','off',...
130              'deletefcn','eval(''delete(get(gcbo,''''userdata''''))'','''')');
131         ax = axes('Position', rect);
132         setappdata(ax,'NonDataObject',[]); % For DATACHILDREN.M
133         set(ud.DeleteProxy,'userdata',ax)
134         set(h,'units',units)
135     else
136         axes(ax);
137         ud = get(ax,'userdata');
138     end
139    
140     % Create color stripe
141     n = size(colormap,1);
142     image([0 1],t,(begslot:endslot)','Tag','TMW_COLORBAR','deletefcn','colorbar(''delete'')'); set(ax,'Ydir','normal')
143     set(ax,'YAxisLocation','right')
144     set(ax,'xtick',[])
145
146     % set up axes deletefcn
147     set(ax,'tag','Colorbar','deletefcn','colorbar(''delete'')')
148    
149 elseif loc(1)=='h', % Append horizontal scale to top of current plot
150    
151     if isempty(ax),
152         units = get(h,'units'); set(h,'units','normalized')
153         pos = get(h,'Position');
154         stripe = 0.075; space = 0.1;
155         set(h,'Position',...
156             [pos(1) pos(2)+(stripe+space)*pos(4) pos(3) (1-stripe-space)*pos(4)])
157         rect = [pos(1) pos(2) pos(3) stripe*pos(4)];
158         ud.origPos = pos;
159
160         % Create axes for stripe and
161         % create DeleteProxy object (an invisible text object in
162         % the target axes) so that the colorbar will be deleted
163         % properly.
164         ud.DeleteProxy = text('parent',h,'visible','off',...
165                               'tag','ColorbarDeleteProxy',...
166                               'handlevisibility','off',...
167              'deletefcn','eval(''delete(get(gcbo,''''userdata''''))'','''')');
168         ax = axes('Position', rect);
169         setappdata(ax,'NonDataObject',[]); % For DATACHILDREN.M
170         set(ud.DeleteProxy,'userdata',ax)
171         set(h,'units',units)
172     else
173         axes(ax);
174         ud = get(ax,'userdata');
175     end
176    
177     % Create color stripe
178     image(t,[0 1],(begslot:endslot),'Tag','TMW_COLORBAR','deletefcn','colorbar(''delete'')'); set(ax,'Ydir','normal')
179     set(ax,'ytick',[])
180
181     % set up axes deletefcn
182     set(ax,'tag','Colorbar','deletefcn','colorbar(''delete'')')
183    
184 else
185   error('COLORBAR expects a handle, ''vert'', or ''horiz'' as input.')
186 end
187
188 if ~isfield(ud,'DeleteProxy'), ud.DeleteProxy = []; end
189 if ~isfield(ud,'origPos'), ud.origPos = []; end
190 ud.PlotHandle = h;
191 set(ax,'userdata',ud)
192 axes(h)
193 set(gcf,'NextPlot',origNextPlot)
194 if ~isempty(legend)
195   legend % Update legend
196 end
197 if nargout>0, handle = ax; end
198
199 %--------------------------------
200 function h = gcda
201 %GCDA Get current data axes
202
203 h = datachildren(gcf);
204 if isempty(h) | any(h == gca)
205   h = gca;
206 else
207   h = h(1);
208 end
Note: See TracBrowser for help on using the browser.