Wednesday, November 17, 2010

print a figure in landscape in matlab

http://www.mathworks.com/support/solutions/en/data/1-3TQNHK/index.html?product=ML&solution=1-3TQNHK

Subject:
How can I print a figure to pdf in landscape with the right scaling in MATLAB 7.3 (R2006b)?

Problem Description:
When I print my figure in landscape to pdf I always see a scaled picture which doesn't fit the paper size.
subplot(2,2,1), plot(randn(100,1));
subplot(2,2,2), plot(randn(200,1));
subplot(2,2,3), plot(randn(300,1));
subplot(2,2,4), plot(randn(400,1));

h=gcf;
set(h,'Position',[50 50 1200 800]);
set(h,'PaperOrientation','landscape');
print(gcf, '-dpdf', 'test.pdf')
Solution:
There are many options to fill the paper size in the printed pdf file:

1. You can change the option "PaperPositionMode" to "auto". This will adjust the size of the printed figure:

h=gcf;
set(h,'PaperPositionMode','auto');
set(h,'PaperOrientation','landscape');
set(h,'Position',[50 50 1200 800]);
print(gcf, '-dpdf', 'test1.pdf')

2. A better solution as changing the "Position" itself would be adjusting the "PaperPosition" to the "PaperSize":
h=gcf;
set(h,'PaperOrientation','landscape');
set(h,'PaperPosition', [1 1 28 19]);
print(gcf, '-dpdf', 'test2.pdf');
Then the option "PaperPositionMode" wouldn't change the appearance even if it is set to "manual".

3. Alternatively you can set "PaperUnits" to "normalized" and "PaperPosition" to "[0 0 1 1]". This will also have the effect of filling the page in the pdf file automatically:
h=gcf;
set(h,'PaperOrientation','landscape');
set(h,'PaperUnits','normalized');
set(h,'PaperPosition', [0 0 1 1]);
print(gcf, '-dpdf', 'test3.pdf');

No comments: