EIDORS_COLOURBAR - create an eidors colourbar with scaling to image usage: eidors_colourbar(max_scale,ref_lev) ref_lev: centre of the colour scale max_scale: max difference from colour scale centre Optional parameter: cb_shrink_move(1) = horizontal shrink (relative) cb_shrink_move(2) = vertial shrink (relative) cb_shrink_move(3) = horizontal move (absolute screen units) The colorbars are removed with colorbar('delete')
0001 function eidors_colourbar(max_scale,ref_lev, cb_shrink_move) 0002 % EIDORS_COLOURBAR - create an eidors colourbar with scaling to image 0003 % usage: eidors_colourbar(max_scale,ref_lev) 0004 % ref_lev: centre of the colour scale 0005 % max_scale: max difference from colour scale centre 0006 % 0007 % Optional parameter: 0008 % cb_shrink_move(1) = horizontal shrink (relative) 0009 % cb_shrink_move(2) = vertial shrink (relative) 0010 % cb_shrink_move(3) = horizontal move (absolute screen units) 0011 % 0012 % The colorbars are removed with colorbar('delete') 0013 0014 % (C) 2005-2010 Andy Adler. License: GPL version 2 or version 3 0015 % $Id: eidors_colourbar.html 2819 2011-09-07 16:43:11Z aadler $ 0016 0017 hh= colorbar; 0018 % make colourbar smaller and closer to axis 0019 if nargin == 3 0020 posn= get(hh,'Position'); 0021 cbsm = cb_shrink_move; 0022 if ~all(cbsm == [1,1,0]); 0023 posn = [posn(1) - cbsm(3), posn(2) + posn(4)*(1-cbsm(2))/2, ... 0024 posn(3) * cbsm(1), posn(4) * cbsm(2)]; 0025 0026 set(hh,'Position', posn ); 0027 0028 end 0029 end 0030 0031 % Stop scale from being too small 0032 if max_scale<abs(ref_lev) 0033 if max_scale < 1e-10; max_scale = 1e-10; end 0034 else 0035 if max_scale/abs(ref_lev) < 1e-4; max_scale = ref_lev*1e-4; end 0036 end 0037 0038 % Get colormap limits and move bottom so we don't see the background colour 0039 ylim = get(hh,'Ylim'); 0040 ylim(1)= ylim(1)+1; 0041 set(hh,'Ylim',ylim); 0042 0043 c_ctr = mean(ylim); 0044 c_max = ylim(2) - c_ctr; 0045 0046 % in order to make the labels clean, we round to a near level 0047 OrdOfMag = 10^floor(log10(max_scale)); 0048 scale_r = OrdOfMag * floor( max_scale / OrdOfMag ); 0049 ref_r = OrdOfMag * round( ref_lev / OrdOfMag ); 0050 0051 tick_vals = [-1:0.5:1]*scale_r + ref_r; 0052 % ref_lev goes to c_ctr. max_scale goes to c_max 0053 tick_locs = (tick_vals - ref_lev)/max_scale * c_max + c_ctr; 0054 set(hh,'YTick', tick_locs'); 0055 set(hh,'YTickLabel', tick_vals'); 0056