function handle=makecolorbar(loc) %MAKECOLORBAR Display color bar (color scale). % MAKECOLORBAR('vert') appends a vertical color scale to % the current axis. COLORBAR('horiz') appends a % horizontal color scale. % % COLORBAR(H) places the colorbar in the axes H. The % colorbar will be horizontal if the axes width > height. % % COLORBAR without arguments either adds a new vertical % color scale or updates an existing colorbar. % % H = COLORBAR(...) returns a handle to the colorbar axis. % Claudio version of the Matlab COLORBAR. % It was modified in order to display only MAPSIZE % of the actual colormap. % Clay M. Thompson 10-9-92 % Copyright (c) 1984-94 by The MathWorks, Inc. % $Revision: 1.3 $ $Date: 1994/01/25 15:51:56 $ global MapSize if nargin<1, loc = 'vert'; end ax = []; if nargin==1, if ~isstr(loc), ax = loc; if ~strcmp(get(ax,'type'),'axes'), error('Requires axes handle.'); end rect = get(ax,'position'); if rect(3) > rect(4), loc = 'horiz'; else loc = 'vert'; end 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(gca,'children'); hasimage = 0; t = []; for i=1:length(ch), if strcmp(get(ch(i),'type'),'image'), hasimage = 1; t = get(ch(i),'UserData'); % Info stored by imshow or imagesc elseif strcmp(get(ch(i),'Type'),'surface'), % Texturemapped surf? if strcmp(get(ch(i),'FaceColor'),'texturemap') hasimage = 2; t = get(ch(i),'UserData'); % Info stored by imshow or imagesc end end end if hasimage, if isempty(t), t = [0.5 size(colormap,1)+0.5]; end else t = caxis; end h = gca; if nargin==0, % Search for existing colorbar ch = get(gcf,'children'); ax = []; for i=1:length(ch), d = get(ch(i),'userdata'); if prod(size(d))==1, if d==h, ax = ch(i); pos = get(ch(i),'Position'); if pos(3)sqrt(eps), ex = log10(max(abs(yticks))); ex = sign(ex)*ceil(abs(ex)); l = text(0,ylim(2)+2*yspace,'x 10', ... 'FontName',get(ax,'FontName'), ... 'FontSize',get(ax,'FontSize'), ... 'FontAngle',get(ax,'FontAngle'), ... 'FontStrikeThrough',get(ax,'FontStrikeThrough'), ... 'FontUnderline',get(ax,'FontUnderline'), ... 'FontWeight',get(ax,'FontWeight')); width = get(l,'Extent'); text(width(3)-xspace,ylim(2)+3.2*yspace,num2str(ex), ... 'FontName',get(ax,'ExpFontName'), ... 'FontSize',get(ax,'ExpFontSize'), ... 'FontAngle',get(ax,'ExpFontAngle'), ... 'FontStrikeThrough',get(ax,'ExpFontStrikeThrough'), ... 'FontUnderline',get(ax,'ExpFontUnderline'), ... 'FontWeight',get(ax,'ExpFontWeight')); end set(ax,'yticklabelmode','manual','yticklabel','') set(ax,'xticklabelmode','manual','xticklabel','') else, % Append horizontal scale to top of current plot if isempty(ax), pos = get(h,'Position'); stripe = 0.075; space = 0.1; set(h,'Position',... [pos(1) pos(2)+(stripe+space)*pos(4) pos(3) (1-stripe-space)*pos(4)]) rect = [pos(1) pos(2) pos(3) stripe*pos(4)]; % Create axes for stripe ax = axes('Position', rect); else axes(ax); end % Create color stripe n = size(colormap,1); image(t,[0 1],[1:n]); set(ax,'Ydir','normal') set(ax,'yticklabelmode','manual') set(ax,'yticklabels','') end set(ax,'userdata',h) set(gcf,'CurrentAxes',h) set(gcf,'Nextplot','Replace') if nargout>0, handle = ax; end