Skip to content

Commit bf85543

Browse files
committed
figuresize padding configurable on all four sides
and reduce the default to just the bottom edge
1 parent 8afa47c commit bf85543

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

figuresize.m

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@ function figuresize( varargin )
2222
% as well as 'mm', 'cm', 'in', or 'pt'. Default 'cm'.
2323
%
2424
% figuresize(w,h,u,padscale)
25-
% - Use <padscale> to adjust (can be given as a single element or
26-
% two-element vector for width/height separately). Default 0.01.
25+
% - Use <padscale> to adjust normalised padding added to the sides.
26+
% Can be 1, 2, or 4 element vector:
27+
% padscale = s % add s*w to the left/right and
28+
% s*h to the top/bottom
29+
% padscale = [sw sh] % add sw*w to the left/right and
30+
% sh*h to the top/bottom
31+
% padscale = [sl sr st sb] % add sl*w to the left, sr*w to the right,
32+
% st*h to the top, and sb*h to the bottom
33+
% Default [0 0 0 0.1] -- add some padding at bottom only due to a
34+
% longstanding limitation of how Matlab produces PDFs at small physical
35+
% sizes, where "small" is approx <10cm in height.
2736

2837

2938
if numel(varargin) == 0
@@ -32,7 +41,7 @@ function figuresize( varargin )
3241
end
3342

3443
if numel(varargin) == 1
35-
figure(varargin{:}); clf; hold on
44+
figure(varargin{:}); clf; hold on; box on
3645
figuresize();
3746
return
3847
end
@@ -44,16 +53,18 @@ function figuresize( varargin )
4453
p.addRequired('height',@(x) isnumeric(x) && all(size(x)==1) );
4554
p.addOptional('units','centimeters',...
4655
@(x) any(strcmpi(x,allowed_units)) );
47-
p.addOptional('padscale',0.01, @(x) isnumeric(x) )
56+
p.addOptional('padscale',[0.0 0.0 0.0 0.1], @(x) isnumeric(x) )
4857

4958
p.parse( varargin{:} );
5059
w = p.Results.width;
5160
h = p.Results.height;
5261
u = p.Results.units;
5362
s = p.Results.padscale;
5463

55-
if numel(s) == 1
56-
s = [s s];
64+
switch numel(s)
65+
case 1, s = [s s s s];
66+
case 2, s = [s(1) s(1) s(2) s(2)];
67+
case 3, error('1, 2, or 4 elements only');
5768
end
5869

5970
switch u
@@ -69,8 +80,8 @@ function figuresize( varargin )
6980
set(gcf,...
7081
'Position',[screenpos(1:2) w h],...
7182
'PaperUnits',u,...
72-
'PaperPosition',[s(1)*w s(2)*h w h],...
73-
'PaperSize',[w*(1+2*s(1)) h*(1+2*s(2))]);
83+
'PaperPosition',[s(1)*w s(4)*h w h],...
84+
'PaperSize',[w*(1+s(1)+s(2)) h*(1+s(3)+s(4))]);
7485

7586
end
7687

@@ -98,4 +109,4 @@ function figuresize( varargin )
98109
% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
99110
% ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
100111
% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
101-
% THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
112+
% THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)