Print figure to pdf -- file size too large

조회 수: 29 (최근 30일)
Tom
Tom 2015년 2월 26일
댓글: Tom 2015년 3월 23일
Hello,
I have a function which creates a plot that has roughly 500,000 data points on it. When I print this figure to a pdf and open the pdf file it takes slightly longer to open than a less complex plot (meaning less data points). A colleague of mine uses the same function to generate the same plot and print to pdf; when he opens this pdf file it may take 5 minutes to display the plot.
He can send me the pdf file generated on his machine and it still takes longer than expected to open the file on my machine.
I was under the impression that when printing to a pdf I was essentially saving an image. Why would a complex plot with more data points take longer to open (as a pdf) than a plot with less data on it if this is true?
Problem is occurring on a Windows 64-bit machine running Matlab 2014b. I am using a Windows 64-bit machine running Matlab 2013b.
I have tried specifying the resolution '-r300' but that does not seem to make a difference.
Is there a different way I can save this figure to a pdf file to avoid this problem?
I have included some sample code which reproduces the results:
t = linspace(0,10,500000);
A = 10;
for i=1:length(t)
x(i) = A*sin(40*pi*t(i))+rand(1)/2;
y(i) = A*cos(40*pi*t(i))+rand(1)/2;
end
hf = figure;
plot(x,y,'linewidth',2);
grid on
title('200 Circles','fontweight','bold','fontsize',14)
xlabel('x','fontweight','bold','fontsize',14)
ylabel('y','fontweight','bold','fontsize',14)
print(hf,'-dpdf','Test_plot.pdf')
Thanks for the help!
-Tom-

채택된 답변

Richard Quist
Richard Quist 2015년 3월 21일
편집: Richard Quist 2015년 3월 21일
I would guess that the PDF is being saved with an embedded image in 13b, and as a fully vectorized file in 14b. Try adding '-opengl' to your print command to force the use of the OpenGL renderer which will embed the figure as an image.
print(hf,'-dpdf','Test_plot.pdf', '-opengl')
Rich
  댓글 수: 1
Tom
Tom 2015년 3월 23일
Rich,
Thanks! It looks like this is just what I was looking for.
Cheers,
-Tom-

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by