views:

421

answers:

3

I generate a figure in MATLAB with large amount of elements (100000+) and want to save it into a PDF file. With zbuffer or painters renderer I've got very large and slowly opened file (over 4 Mb) - all points are in vector format. Using OpenGL renderer rasterize the figure in PDF, ok for the plot, but not good for text labels. The file size is about 150 Kb.

Try this simplified code, for example:

x=linspace(1,10,100000);
y=sin(x)+randn(size(x));
plot(x,y,'.')
set(gcf,'Renderer','zbuffer')
print -dpdf -r300 testpdf_zb
set(gcf,'Renderer','painters')
print -dpdf -r300 testpdf_pa
set(gcf,'Renderer','opengl')
print -dpdf -r300 testpdf_op

The actual figure is much more complex with several axes and different types of plots.

Is there a way to rasterize the figure, but keep text labels as vectors?

Another problem with OpenGL is that is does not work in terminal mode (-nosplash -nodesktop -nodisplay) under Mac OSX. Looks like OpenGL is not supported. I have to use terminal mode for automation. The MATLAB version I run is 2007b. Mac OSX server 10.4.

+1  A: 
AVB
Vector format can be compressed, but the file opens very slow anyway drawing all the vector elements. This is why I'd like to rasterize the figure. Thanks for the idea with image. Seems complicated but doable.
yuk
A: 

If at all possible you should try to subsample your problem before building the illustration. If you are plotting points on a curve then 10,000 is probably more than you need. A modern printer is only about 600 DPI afterall.

If the points are illustrating a cloud with some density properties, a better solution may be to build a two dimensional histogram first, and illustrate that with imshow or imagesc.

If multiple clouds are being illustrated with different colors you may be interested in building one such image for each cloud and the combining them with transparency.

BlessedKey
The real data does not look like cloud. I need to show the raw data as is. I used this simple example just to show the problem.
yuk
A: 

If you don't want to go with a 2D histogram (i.e. an image where pixel brightness corresponds to density of points) as BlessedKey suggests, it looks like the only good way is to do the rasterizing yourself, as mentioned by AB.

getframe followed by frame2im seems to be the way to go for that. Unfortunately, getframe returns empty if you run with -nodisplay. Therefore, you'd have to save the figure as .fig, and on another computer run a script that opens the figure, gets the content of the axes with getframe, displays the image from getframe and then saves to pdf.

As an alternative to simple plotting or a 2D histogram, you may want to look into scattercloud, which combines plotting the points with density information, by the way.

Jonas