Insets - Create insets in current axes. Create insets (= small figures) in current axes. Insets are laid out side by side from left to right. The number of insets is determined by the number of output parameters. USAGE [a,b,...] = Insets(location,size,<options>) location 'topleft', 'top', 'topright', 'left', 'center', 'right', 'bottomleft', 'bottom', or 'bottomright' size total [h v] size of insets, as proportions of current axes (after subtracting margins) <options> optional list of property-value pairs (see table below) ========================================================================= Properties Values ------------------------------------------------------------------------- 'margin' margin around insets, as a proportion of figure size (default = 0.1) ========================================================================= EXAMPLE % Create a figure and add the main plot figure;plot(x,y); % Create 3 insets in the top right corner, leaving 10% of the available % width and height for margins (default). In total, the insets will occupy % half of the remaining width, and one quarter of the remaining height. [a,b,c] = Insets('topright',[0.5 0.25]); % Plot data in each of the insets axes(a);plot(x,z1); axes(b);plot(x,z2); axes(c);plot(x,z3);
0001 function [a,varargout] = Insets(location,s,varargin) 0002 0003 %Insets - Create insets in current axes. 0004 % 0005 % Create insets (= small figures) in current axes. Insets are laid out side 0006 % by side from left to right. The number of insets is determined by the 0007 % number of output parameters. 0008 % 0009 % USAGE 0010 % 0011 % [a,b,...] = Insets(location,size,<options>) 0012 % 0013 % location 'topleft', 'top', 'topright', 'left', 'center', 'right', 0014 % 'bottomleft', 'bottom', or 'bottomright' 0015 % size total [h v] size of insets, as proportions of current axes 0016 % (after subtracting margins) 0017 % <options> optional list of property-value pairs (see table below) 0018 % 0019 % ========================================================================= 0020 % Properties Values 0021 % ------------------------------------------------------------------------- 0022 % 'margin' margin around insets, as a proportion of figure size 0023 % (default = 0.1) 0024 % ========================================================================= 0025 % 0026 % EXAMPLE 0027 % 0028 % % Create a figure and add the main plot 0029 % figure;plot(x,y); 0030 % % Create 3 insets in the top right corner, leaving 10% of the available 0031 % % width and height for margins (default). In total, the insets will occupy 0032 % % half of the remaining width, and one quarter of the remaining height. 0033 % [a,b,c] = Insets('topright',[0.5 0.25]); 0034 % % Plot data in each of the insets 0035 % axes(a);plot(x,z1); 0036 % axes(b);plot(x,z2); 0037 % axes(c);plot(x,z3); 0038 0039 % Copyright (C) 2009-2011 by Michaƫl Zugaro 0040 % 0041 % This program is free software; you can redistribute it and/or modify 0042 % it under the terms of the GNU General Public License as published by 0043 % the Free Software Foundation; either version 3 of the License, or 0044 % (at your option) any later version. 0045 0046 % Default values 0047 margin = 0.1; 0048 0049 % Check number of parameters 0050 if nargin < 2, 0051 error('Incorrect number of parameters (type ''help <a href="matlab:help Insets">Insets</a>'' for details).'); 0052 end 0053 0054 % Check parameters 0055 if any(s>1|s<0), 0056 error('Sizes must be expressed as proportion [0..1] of total figure size (type ''help <a href="matlab:help Insets">Insets</a>'' for details).'); 0057 end 0058 location = lower(location); 0059 if ~isastring(location,'topleft','top','topright','left','center','right','bottomleft','bottom','bottomright'), 0060 error('Incorrect location (type ''help <a href="matlab:help Insets">Insets</a>'' for details).'); 0061 end 0062 0063 % Parse parameter list 0064 for i = 1:2:length(varargin), 0065 if ~ischar(varargin{i}), 0066 error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help Insets">Insets</a>'' for details).']); 0067 end 0068 switch(lower(varargin{i})), 0069 case 'margin', 0070 margin = lower(varargin{i+1}); 0071 if ~isdscalar(margin,'>=0','<=1'), 0072 error('Incorrect value for property ''margin'' (type ''help <a href="matlab:help Insets">Insets</a>'' for details).'); 0073 end 0074 otherwise, 0075 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help Insets">Insets</a>'' for details).']); 0076 end 0077 end 0078 0079 0080 % Position and size of current axes 0081 p = get(gca,'position'); 0082 axesBottom = p(2); 0083 axesTop = p(2)+p(4); 0084 axesLeft = p(1); 0085 axesRight = p(1)+p(3); 0086 axesWidth = p(3); 0087 axesHeight = p(4); 0088 0089 % Inset margins 0090 hMargin = margin*axesWidth; 0091 vMargin = margin*axesHeight; 0092 0093 % Size of each mini figure 0094 n = nargout; 0095 dx = s(1)/n*(axesWidth-2*hMargin); 0096 dy = s(2)*(axesHeight-2*vMargin); 0097 0098 % Start point 0099 switch(lower(location)), 0100 case 'topleft', 0101 x0 = axesLeft+hMargin; 0102 y0 = axesTop-dy-vMargin; 0103 case 'top', 0104 x0 = axesLeft+hMargin+dx*n/2; 0105 y0 = axesTop-dy-vMargin; 0106 case 'topright', 0107 x0 = axesRight-hMargin-dx*n; 0108 y0 = axesTop-dy-vMargin; 0109 case 'left', 0110 x0 = axesLeft+hMargin; 0111 y0 = axesBottom+vMargin+dy/2; 0112 case 'center', 0113 x0 = axesLeft+hMargin+dx*n/2; 0114 y0 = axesBottom+vMargin+dy/2; 0115 case 'right', 0116 x0 = axesRight-hMargin-dx*n; 0117 y0 = axesBottom+vMargin+dy/2; 0118 case 'bottomleft', 0119 x0 = axesLeft+hMargin; 0120 y0 = axesBottom+vMargin; 0121 case 'bottom', 0122 x0 = axesLeft+hMargin+dx*n/2; 0123 y0 = axesBottom+vMargin; 0124 case 'bottomright', 0125 x0 = axesRight-hMargin-dx*n; 0126 y0 = axesBottom+vMargin; 0127 end 0128 0129 % Create all axes 0130 for i = 1:n, 0131 varargout{i} = axes('position',[x0+(i-1)*dx y0 dx dy]); 0132 end 0133 0134 % Matlab cannot return only varargout, it needs at least one explicit parameter... 0135 a = varargout{1}; 0136 varargout = {varargout{2:end}};