function handle=colorbar(arg1, arg2, arg3) %COLORBAR Display color bar (color scale). % This file is from MATLAB R12 % COLORBAR('vert') appends a vertical color scale to the current % axes. COLORBAR('horiz') appends a horizontal color scale. % % COLORBAR(H) places the colorbar in the axes H. The colorbar will % be horizontal if the axes H width > height (in pixels). % % COLORBAR without arguments either adds a new vertical color scale % or updates an existing colorbar. % % H = COLORBAR(...) returns a handle to the colorbar axes. % % COLORBAR(...,'peer',AX) creates a colorbar associated with axes AX % instead of the current axes. % % See also IMAGESC. % Clay M. Thompson 10-9-92 % Copyright 1984-2000 The MathWorks, Inc. % $Revision: 5.41 $ $Date: 2000/07/27 14:25:45 $ narg = nargin; if narg<2 haxes = gca; hfig = gcf; if narg<1 loc = 'vert'; % Default mode when called without arguments. else % Peer must be followed by a valid axes handle. if strcmp(arg1,'peer') error('Parameter ''peer'' must be followed by an axes handle.'); end loc = arg1; end elseif narg == 2 % This is the case ONLY when peer and a handle is passed. if strcmp(arg1,'peer') if ishandle(arg2) & strcmp(get(arg2, 'type'), 'axes') haxes = arg2; hfig = get(haxes,'parent'); loc = 'vert'; narg = 0; else % If second arg is not a valid axes handle error('Second argument must be a scalar axes handle.'); end else error('Unknown command option.'); end else % For three arguments the first must be the mode or a axes handle, % second must be the string 'peer' and third must be the peer axes handle. loc = arg1; if strcmp(arg2,'peer') if ishandle(arg3) & strcmp(get(arg3, 'type'), 'axes') haxes = arg3; hfig = get(haxes,'parent'); narg = 1; else error('Third argument must be a scalar axes handle.'); end else error('Unknown command option.'); end end % Catch colorbar('delete') special case -- must be called by the deleteFcn. if narg==1 & strcmp(loc,'delete') ax = gcbo; % % If called from DeleteProxy, delete the colorbar axes % if strcmp(get(ax,'tag'),'ColorbarDeleteProxy') cbo = ax; ax = get(cbo,'userdata'); if ishandle(ax) ud = get(ax,'userdata'); % Do a sanity check before deleting colorbar if isfield(ud,'DeleteProxy') & ... isequal(ud.DeleteProxy,cbo) & ... ishandle(ax) try delete(ax) end end end else % % If called from the colorbar image resize the original axes % if strcmp(get(ax,'tag'),'TMW_COLORBAR') ax=get(ax,'parent'); end ud = get(ax,'userdata'); if isfield(ud,'PlotHandle') & ... ishandle(ud.PlotHandle) & ... isfield(ud,'origPos') & ... ~isempty(ud.origPos) units = get(ud.PlotHandle,'units'); set(ud.PlotHandle,'units','normalized'); set(ud.PlotHandle,'position',ud.origPos); set(ud.PlotHandle,'units',units); legH=legend(ud.PlotHandle); if ~isempty(legH) & ishandle(legH) legend('RecordSize',ud.PlotHandle); legend(legH) % Update legend end end if isfield(ud,'DeleteProxy') & ishandle(ud.DeleteProxy) try delete(ud.DeleteProxy) end end end return end % If called with COLORBAR(H) or for an existing colorbar, don't change % the NextPlot property. ax = []; changeNextPlot = 1; if narg==1 if ishandle(loc) ax = loc; if ~strcmp(get(ax,'type'),'axes'), error('Requires axes handle.'); end units = get(ax,'units'); set(ax,'units','pixels'); rect = get(ax,'position'); set(ax,'units',units); if rect(3) > rect(4) loc = 'horiz'; else loc = 'vert'; end changeNextPlot = 0; end end % Determine color limits by context. If any axes child is an image % use scale based on size of colormap, otherwise use current CAXIS. ch = get(gcda(hfig,haxes),'children'); hasimage = 0; t = []; cdatamapping = 'direct'; for i=1:length(ch), typ = get(ch(i),'type'); if strcmp(typ,'image'), hasimage = 1; cdatamapping = get(ch(i), 'CDataMapping'); elseif strcmp(typ,'surface') & ... strcmp(get(ch(i),'FaceColor'),'texturemap') % Texturemapped surf hasimage = 2; cdatamapping = get(ch(i), 'CDataMapping'); elseif strcmp(typ,'patch') | strcmp(typ,'surface') cdatamapping = get(ch(i), 'CDataMapping'); end end if ( strcmp(cdatamapping, 'scaled') ) % Treat images and surfaces alike if cdatamapping == 'scaled' t = caxis(haxes); d = (t(2) - t(1))/size(colormap(haxes),1); t = [t(1)+d/2 t(2)-d/2]; else if hasimage, t = [1, size(colormap(haxes),1)]; else t = [1.5 size(colormap(haxes),1)+.5]; end end h = gcda(hfig,haxes); if narg==0, % Search for existing colorbar ch = get(findall(hfig,'type','image','tag','TMW_COLORBAR'),{'parent'}); ax = []; for i=1:length(ch), ud = get(ch{i},'userdata'); d = ud.PlotHandle; if prod(size(d))==1 & isequal(d,h), ax = ch{i}; pos = get(ch{i},'Position'); if pos(3)0 handle = ax; end %-------------------------------- function h = gcda(hfig, haxes) %GCDA Get current data axes h = datachildren(hfig); if isempty(h) | any(h == haxes) h = haxes; else h = h(1); end