Documentation of colorbar4


Global Index (all files) (short | long) | Local Index (files in subdir) (short | long)


Function Synopsis

cb = colorbar4(loc, children, force);

Help text

  cb = colorbar4(loc, children, 'force');

  where loc = 'l', 'r', 'b', 't' puts a single colorbar
  at the left, right, bottom, or top of the current
  figure.

  children = the children you want the subplot to refer to

  force = 1 will force the subplot on the figure, 
  regardless of whether it fits or not.  Naturally,
  the default is force = 0.


Listing of function colorbar4

function cb = colorbar4(loc, children, force);


if nargin < 1; loc = 'r'; end;
if nargin < 2; children = gca; end;
if nargin < 3; force = 0; end;

Paper_Orient = get(gcf, 'PaperOrientation');
if strcmp(lower(Paper_Orient(1)), 'r');
  error('Sorry, I have not tested Rotated orientations');
end

Child = get(gcf, 'Children');
ind = find(ismember(Child, children));
if any(~ismember(children, Child));
  error('One or more children do not belong to this figure');
end

pos = repmat(NaN, [length(ind) 4]);
for i = 1:length(ind);
  pos(i,:) = get(Child(ind(i)), 'Position');
end

minx = min(pos(:,1));
maxx = max(pos(:,1)+pos(:,3));
miny = min(pos(:,2));
maxy = max(pos(:,2)+pos(:,4));

if strcmp(lower(loc(1)), 'r');

  if (1-maxx > 0.075) | force;
    PlotSz = (maxy-miny)./(1+0.5*(maxy-miny));
    ax = axes('Position', ...
	      [maxx+0.025 miny+0.5*((maxy-miny)-PlotSz) ...
	       0.025 PlotSz]);
    YAxisLoc = 'Right';
    XAxisLoc = 'Bottom';
  else
    error('There might not be enough room.  Try a different location');
  end
  
elseif strcmp(lower(loc(1)), 'l');
  
  if minx > 0.1 | force;
    PlotSz = (maxy-miny)./(1+0.5*(maxy-miny));
    ax = axes('Position', ...
	      [minx-0.075 miny+0.5*((maxy-miny)-PlotSz) ...
	         0.025 PlotSz]);
    YAxisLoc = 'Left';
    XAxisLoc = 'Bottom';
  else
    error('There might not be enough room.  Try a different location');
  end
  
elseif strcmp(lower(loc(1)), 'b');
  
  if miny > 0.1 | force;
    PlotSz = (maxx-minx)./(1+0.5*(maxx-minx));
    ax = axes('Position', ...
	      [minx+0.5*((maxx-minx)-PlotSz) miny-0.075 ...
	         PlotSz 0.025], ...
	      'XAxisLocation', 'bottom', ...
	      'YTick', []);
    YAxisLoc = 'Left';
    XAxisLoc = 'Bottom';
  else
    error('There might not be enough room.  Try a different location');
  end

elseif strcmp(lower(loc(1)), 't');
  
  if (1-maxy) > 0.125 | force;
    PlotSz = (maxx-minx)./(1+0.5*(maxx-minx));
    ax = axes('Position', ...
	      [minx+0.5*((maxx-minx)-PlotSz) maxy+0.05 ...
	         PlotSz 0.025], ...
	      'XAxisLocation', 'top', ...
	      'YTick', []);
    YAxisLoc = 'Left';
    XAxisLoc = 'Top';
  else
    error('There might not be enough room.  Try a different location');
  end

end

cb = colorbar(ax);
set(ax, 'XAxisLocation', XAxisLoc, 'YAxisLocation', YAxisLoc);