


UIcolorshift Creates an interactive colorbar. UIcolorshift adds a (vertical) colorbar to the current axes. This colorbar can be used to shift or rescale the color mapping in the current axes. Clicking near the top of the colorbar axes up or down (right or left for horizontal colorbars) changes the value mapped to the top color scale limit. Similarly, clicking near the bottom changes the value mapped to the bottom color scale limit. Clicking elsewhere and dragging cyclically shifts the color map. This shift is applied to the whole figure. UIcolorshift(ARG1,...) takes the same arguments as COLORBAR. H = UIcolorshift(...) returns a handle to the colorbar axes.


0001 function h = UIcolorshift(varargin) 0002 %UIcolorshift Creates an interactive colorbar. 0003 % UIcolorshift adds a (vertical) colorbar to the current axes. This 0004 % colorbar can be used to shift or rescale the color mapping in the 0005 % current axes. Clicking near the top of the colorbar axes 0006 % up or down (right or left for horizontal colorbars) changes the value 0007 % mapped to the top color scale limit. Similarly, clicking near the 0008 % bottom changes the value mapped to the bottom color scale limit. 0009 % 0010 % Clicking elsewhere and dragging cyclically shifts the color map. This 0011 % shift is applied to the whole figure. 0012 % 0013 % UIcolorshift(ARG1,...) takes the same arguments as COLORBAR. 0014 % 0015 % H = UIcolorshift(...) returns a handle to the colorbar axes. 0016 0017 %%%%%%%%%%%%%%%%%%%%%%%%% Create the Colorbar %%%%%%%%%%%%%%%%%%%%%%%% 0018 target = gca; 0019 fighdl = gcf; 0020 h = colorbar(varargin{:}); % create or refresh an existing colorbar 0021 %h = find_colorbar(target); % <=R13 only 0022 0023 %%%%%%%%%%%%%%%%%%%%% Get a handle to the Colorbar %%%%%%%%%%%%%%%%%%% 0024 cimage = findobj(h, 'Type', 'image'); 0025 0026 cbar_pos = get(h, 'Position'); 0027 ax_pos = get(target, 'Position'); 0028 if (cbar_pos(1) > sum(ax_pos([1,3]))), mode = 'V'; 0029 else, mode = 'H'; 0030 end 0031 0032 %%%%%%%%%%%%%%%%%%%%%%%%% Assign the Callback %%%%%%%%%%%%%%%%%%%%%%%% 0033 userdata = get(h,'UserData'); 0034 userdata.fighdl = fighdl; 0035 userdata.cbrhdl = h; 0036 userdata.target = target; 0037 userdata.cimage = cimage; 0038 userdata.mode = mode; 0039 set(h, 'UserData', userdata, 'ButtonDownFcn', @CB_colorshift); 0040 0041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Cleanup %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0042 if (nargout == 0), clear h; end 0043 axes(target); % reset current axes