Skip to content

Instantly share code, notes, and snippets.

@raviramanathan
Created July 22, 2014 14:06
Show Gist options
  • Save raviramanathan/5e7b6ed0efceaa3d38fa to your computer and use it in GitHub Desktop.
Save raviramanathan/5e7b6ed0efceaa3d38fa to your computer and use it in GitHub Desktop.
Setting Paper Size in Matlab Figures
I repeatedly look for the code to specify paper size and attributes in matlab for figures.
Here is how to do it :
hFig = gcf;
%# centimeters units
X = 42.0; %# A3 paper size
Y = 29.7; %# A3 paper size
% Or
X = 8.0; Y = 12.0 ; % custom size
xMargin = 1; %# left/right margins from page borders
yMargin = 1; %# bottom/top margins from page borders
xSize = X - 2*xMargin; %# figure size on paper (widht & hieght)
ySize = Y - 2*yMargin; %# figure size on paper (widht & hieght)
%# figure size printed on paper
set(hFig, 'PaperUnits','centimeters')
set(hFig, 'PaperSize',[X Y])
set(hFig, 'PaperPosition',[xMargin yMargin xSize ySize])
set(hFig, 'PaperOrientation','portrait')
% thanks for the folks on Matlab Forums & Stackoverflow for the codet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment