function handle=thincolorbar(arg1, arg2, arg3) %THINCOLORBAR Display color bar (color scale). % % This is a modification of Matlab's colorbar function that % generates thinner colorbars. % % THINCOLORBAR('vert') appends a vertical color scale to the current % axes. THINCOLORBAR('horiz') appends a horizontal color scale. % % THINCOLORBAR(H) places the thincolorbar in the axes H. % The thincolorbar will be horizontal % if the axes H width > height (in pixels). % % THINCOLORBAR without arguments either adds a new vertical color % scale or updates an existing thincolorbar. % % H = THINCOLORBAR(...) returns a handle to the thincolorbar axes. % % THINCOLORBAR(...,'peer',AX) creates a thincolorbar associated with % axes AXinstead of the current axes. % % See also IMAGESC. % Clay M. Thompson 10-9-92 % Copyright 1984-2002 The MathWorks, Inc. % $Revision: 1.1 $ $Date: 2006/06/27 15:35:11 $ narg = nargin; % when this is done doing whatever it does % gcf and gca should be what they were when we got here % so get them now GCF = gcf; GCA = gca; 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 ColorbarDeleteProxy, 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,'ColorbarDeleteProxy') & ... isequal(ud.ColorbarDeleteProxy,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) % Get position and orientation of colorbar being deleted delpos = get(ax,'Position'); if delpos(3) rect(4) loc = 'horiz'; else loc = 'vert'; end end end % the axes handle, shorter name h = haxes; % Catch attempt to add colorbar to a colorbar or legend % if the axes h is a colorbar or legend (according to tag) % reset it to the PlotHandle field of its userdata tagstr = get(h,'tag'); if strcmpi('Legend',tagstr) | strcmpi('Colorbar',tagstr) ud = get(h,'userdata'); if isfield(ud,'PlotHandle') h = ud.PlotHandle; else % If handle is a dying or mutant colorbar or legend % do nothing. % but before going, be sure to reset current figure and axes set(0,'currentfigure',GCF); set(gcf,'currentaxes',GCA); return; 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,h),'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(h); d = (t(2) - t(1))/size(colormap(h),1); t = [t(1)+d/2 t(2)-d/2]; else if hasimage, t = [1, size(colormap(h),1)]; else t = [1.5 size(colormap(h),1)+.5]; end end oldloc = 'none'; oldax = []; if ~cbarinaxis % Search for existing colorbar (parents of TMW_COLORBAR tagged images) 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 the plothandle (axis) of the colorbar is our axis if isequal(d,h) pos = get(ch{i},'Position'); if pos(3)0 handle = ax; end % Finally, before going, be sure to reset current figure and axes set(0,'currentfigure',GCF); set(gcf,'currentaxes',GCA); %-------------------------------- 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