


NICE Custom plot prettification.
The function NICE is a macro for Matlab graphics settings, and its
behavior depends on the contents of the current axes.
If the plot contains only 2-D objects (i.e., objects with empty ZData)
NICE sets the Y-limits depending on the data:
Data Range Gives Limits
[ 0,1] [-0.2 1.2]
[-1,1] [-1.2 1.2]
[ 0,B] [-0.2 1.2]*B
[-A,B] [-1.2 1.2]*C, where C=MAX(ABS(A,B))
where the first condition that matches is used.
For data with range [P,Q], the X-limits are set to [P-Z, Q+Z], where
Z=0.02*MAX(ABS(P,Q)).
If the plot contains objects with non-empty ZData, 3-D visualization
aids are set, including: standard lighting conditions (existing lights
are removed), standard view angle for 3-D rotation and interpolated
shading (where possible).

0001 function nice 0002 %NICE Custom plot prettification. 0003 % The function NICE is a macro for Matlab graphics settings, and its 0004 % behavior depends on the contents of the current axes. 0005 % 0006 % If the plot contains only 2-D objects (i.e., objects with empty ZData) 0007 % NICE sets the Y-limits depending on the data: 0008 % Data Range Gives Limits 0009 % [ 0,1] [-0.2 1.2] 0010 % [-1,1] [-1.2 1.2] 0011 % [ 0,B] [-0.2 1.2]*B 0012 % [-A,B] [-1.2 1.2]*C, where C=MAX(ABS(A,B)) 0013 % where the first condition that matches is used. 0014 % For data with range [P,Q], the X-limits are set to [P-Z, Q+Z], where 0015 % Z=0.02*MAX(ABS(P,Q)). 0016 % 0017 % If the plot contains objects with non-empty ZData, 3-D visualization 0018 % aids are set, including: standard lighting conditions (existing lights 0019 % are removed), standard view angle for 3-D rotation and interpolated 0020 % shading (where possible). 0021 0022 childs = get(gca, 'Children'); 0023 if (length(childs) == 1), childs = childs([1,1]); end; % ensure get(childs, prop) always returns cell 0024 0025 texts = childs(strcmp(get(childs, 'Type'), 'text')); % split into different types 0026 lights = childs(strcmp(get(childs, 'Type'), 'light')); 0027 images = childs(strcmp(get(childs, 'Type'), 'image')); 0028 patchs = childs(strcmp(get(childs, 'Type'), 'patch')); 0029 surfs = childs(strcmp(get(childs, 'Type'), 'surface')); 0030 lines = childs(strcmp(get(childs, 'Type'), 'line')); 0031 0032 surfpatch = [surfs(:); patchs(:)]; 0033 surfpatchline = [surfs(:); patchs(:); lines(:)]; 0034 twoD = all(cellfun('isempty', get([lines,surfs,patchs], 'ZData'))); 0035 0036 if (twoD) 0037 allxdata = get(surfpatchline, 'XData'); allydata = get(surfpatchline, 'YData'); 0038 xdata = []; ydata = []; 0039 for k = 1:length(surfpatchline) 0040 xdata = [xdata(:); allxdata{k}(:)]; ydata = [ydata(:); allydata{k}(:)]; 0041 end 0042 0043 ydatlims = minmax(ydata); 0044 maxabs = max(abs([ydatlims,1])); 0045 if (ydatlims(1) < 0), ylim = [-1.2, 1.2]*maxabs; 0046 else, ylim = [-0.2, 1.2]*maxabs; 0047 end 0048 0049 xdatlims = minmax(xdata); 0050 pad = max(0.02*abs(xdatlims)); pad = [-pad pad]; 0051 xlim = xdatlims + pad; 0052 0053 set(gca, 'YLim', ylim, 'XLim', xlim); 0054 zoom reset; 0055 0056 elseif (~isempty(surfpatch)) 0057 0058 axis tight; set(gca,'CameraViewAngleMode', 'manual', 'CameraViewAngle', 9); 0059 0060 interpable = ~cellfun('isempty', get(surfpatch, {'CData'})); 0061 set(surfpatch(interpable), 'FaceColor', 'interp', 'EdgeColor', 'none'); 0062 0063 material dull; 0064 lighting gouraud; % not as nice as phong lighting, but faster to render 0065 lightangle(90,60); lightangle(270,10); 0066 0067 end