addGradientToAxes

PURPOSE ^

addGradientToAxes Add some shading to the axes

SYNOPSIS ^

function addGradientToAxes( axh )

DESCRIPTION ^

addGradientToAxes  Add some shading to the axes

   gpubench.addGradientToAxes(axh)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function addGradientToAxes( axh )
0002 %addGradientToAxes  Add some shading to the axes
0003 %
0004 %   gpubench.addGradientToAxes(axh)
0005 
0006 %   Copyright 2011 The MathWorks, Inc.
0007 
0008 % Pick colors for the top and bottom of the canvas
0009 topCol = [0.87 0.87 0.87];
0010 botCol = [0.98 0.98 0.98];
0011 
0012 % First, remove any existing shading
0013 p = findall( axh, 'Tag', 'FunkyAxes:AxesBackground' );
0014 if ~isempty( p )
0015     delete( p );
0016 end
0017 xlim = get( axh, 'XLim' );
0018 ylim = get( axh, 'YLim' );
0019 if strcmpi( get( axh, 'YDir' ), 'Reverse' )
0020     ylim = fliplr( ylim );
0021 end
0022 zlim = get( axh, 'ZLim' );
0023 clim = get( axh, 'CLim' );
0024 % Make sure the grid appears over the patch
0025 set( axh, 'Layer', 'top' );
0026 
0027 % Now create the patch
0028 r = [ topCol(1)*[1 1]  botCol(1)*[1 1] ];
0029 g = [ topCol(2)*[1 1]  botCol(2)*[1 1] ];
0030 b = [ topCol(3)*[1 1]  botCol(3)*[1 1] ];
0031 cdata = cat( 3, r, g, b );
0032 % A bug in patch means that it sometimes resets CLim!
0033 ptch = patch( ...
0034     'Parent', axh, ...
0035     'XData', [xlim,fliplr(xlim)], ...
0036     'YData', [ylim(1)*[1 1] ylim(2)*[1 1]], ...
0037     'ZData', -inf*ones(1,4), ...
0038     'CData', cdata, ...
0039     'FaceColor', 'interp', ...
0040     'FaceLighting', 'none', ...
0041     'Tag', 'FunkyAxes:AxesBackground', ...
0042     'HandleVisibility', 'off', ...
0043     'HitTest', 'off' );
0044 set( axh, 'CLim', clim );
0045 % Make sure the patch is at the bottom!
0046 iSendToBack( axh, ptch )
0047 hold( axh, 'on' );
0048 % Listen for changes in the limits so that we don't see patch edges
0049 hgax = handle( axh );
0050 setappdata( axh, 'LimitListeners', {
0051     handle.listener( hgax, findprop( hgax, 'XLim' ), 'PropertyPostSet', @iUpdatePatch )
0052     handle.listener( hgax, findprop( hgax, 'YLim' ), 'PropertyPostSet', @iUpdatePatch )
0053     } );
0054 
0055 
0056     function iUpdatePatch(~,~)
0057         if ~isempty( ptch ) && ishandle( ptch )
0058             xlim = get( axh, 'XLim' );
0059             ylim = get( axh, 'YLim' );
0060             zlim = get( axh, 'ZLim' );
0061             set( ptch, ...
0062                 'XData', [xlim,fliplr(xlim)], ...
0063                 'YData', [ylim(1)*[1 1] ylim(2)*[1 1]], ...
0064                 'ZData', zlim(1)*ones(1,4) );
0065         end
0066     end % iUpdatePatch
0067 
0068 end % addGradientToAxes
0069 
0070 function iSendToBack( axh, bg )
0071 % Send an HG object to the back of the display stack
0072 children = findall( axh,'Parent',axh );
0073 set( axh, 'Children', [children(children~=bg);bg] )
0074 end % iSendToBack

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