addAreaShadows

PURPOSE ^

addAreaShadows add shadows to any patches in the axes

SYNOPSIS ^

function addAreaShadows( axh )

DESCRIPTION ^

addAreaShadows  add shadows to any patches in the axes

   gpubench.addAreaShadows(axh)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function addAreaShadows( axh )
0002 %addAreaShadows  add shadows to any patches in the axes
0003 %
0004 %   gpubench.addAreaShadows(axh)
0005 
0006 %   Copyright 2011 The MathWorks, Inc.
0007 
0008 % The color to use for the shadow. Should probably adapt to the background,
0009 % but for now let's just hard-code it.
0010 shadowColor = 0.6*[1 1 1];
0011 
0012 % The shadow size is expressed as a ratio of the axes width/height
0013 shadowSize = 1/300;
0014 
0015 % First remove any existing ones
0016 l = findall( axh, 'Tag', 'FunkyAxes:AreaShadow' );
0017 if ~isempty( l )
0018     delete( l )
0019 end
0020 
0021 % Work out the axes limits and correspopnding shadow offsets
0022 dx = diff( get( axh, 'XLim' ) )*shadowSize;
0023 dy = -diff( get( axh, 'YLim' ) )*shadowSize;
0024 if strcmpi( get( axh, 'XDir' ), 'Reverse' )
0025     dx = -dx;
0026 end
0027 if strcmpi( get( axh, 'YDir' ), 'Reverse' )
0028     dy = -dy;
0029 end
0030 z0 = get( axh, 'ZLim' );
0031 z0 = z0(1) - max(0.1,diff( z0 )*shadowSize);
0032 
0033 % Find all existing patches in the axes, excluding any background
0034 patches = findobj( axh, 'type', 'patch' );
0035 patches( strcmpi( get( patches, 'Tag' ), 'FunkyAxes:AxesBackground' ) ) = [];
0036 props_to_copy = {
0037     'XData'
0038     'YData'
0039     'ZData'
0040     'FaceColor'
0041     'EdgeColor'
0042     'LineStyle'
0043     'LineWidth'
0044     };
0045 
0046 % Now go through each patch, copying various properties into a new "shadow"
0047 % patch.
0048 vals = cell( size( props_to_copy ) );
0049 l = -1*ones( size( patches ) );
0050 for jj=1:numel( patches )
0051     l(jj) = patch( nan, nan, nan, ...
0052         'Tag', 'FunkyAxes:AreaShadow', ...
0053         'Parent', axh );
0054     for kk=1:numel( props_to_copy )
0055         vals{kk} =  get( patches(jj), props_to_copy{kk} );
0056     end
0057     args = [props_to_copy,vals]';
0058     set( l(jj), args{:} );
0059     
0060     set( l(jj), ...
0061         'FaceColor', shadowColor, ...
0062         'EdgeColor', shadowColor, ...
0063         'XData', get( patches(jj), 'XData' ) + dx, ...
0064         'YData', get( patches(jj), 'YData' ) + dy, ...
0065         'ZData', z0*ones( size( get( patches(jj), 'XData' ) ) ), ...
0066         'HitTest', 'off' );
0067 end

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.