节省“繁重"在MATLAB中转换为PDF格式-渲染问题 [英] Saving "heavy" figure to PDF in MATLAB - rendering problem

查看:189
本文介绍了节省“繁重"在MATLAB中转换为PDF格式-渲染问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MATLAB中生成了一个包含大量元素(100000+)的图形,并希望将其保存到PDF文件中.使用zbuffer或painters渲染器,我得到了一个非常大且缓慢打开的文件(超过4 Mb)-所有点均为矢量格式.使用OpenGL渲染器栅格化PDF中的图形,可以使用该图,但不适用于文本标签.文件大小约为150 Kb.

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?

OpenGL的另一个问题是在Mac OSX下的终端模式(-nosplash -nodesktop -nodisplay)下不起作用.看起来不支持OpenGL.我必须使用终端模式进行自动化.我运行的MATLAB版本是2007b. Mac OSX服务器10.4.

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.

推荐答案

这很有趣.您的问题不是Matlab,而是Ghostscript(Matlab至少在Windows上是通过调用Ghostscript创建PDF的).当我跑步

This is a funny one. Your problem is not Matlab, it's Ghostscript (Matlab creates PDFs by calling Ghostscript, at least on Windows). When I run

x=linspace(1,10,100000);
y=sin(x)+randn(size(x));
plot(x,y,'.')
print -dpsc2 test.ps

我有一个2Mb PS文件(当然是所有矢量),压缩后变成了164Kb ZIP.将PS转换为PDF时,人们可能希望获得几乎相同的结果,但是ps2pdf test.ps生成了4Mb文件!

I've got a 2Mb PS file (all vector, of course), which when compressed became a 164Kb ZIP. One would expect to get more-or-less the same result when converting PS to PDF, but ps2pdf test.ps produced your 4Mb file!

由于您使用的是Mac,因此您可能拥有Distiller.我会试一试—如上所述生成PS文件,然后通过Distiller运行它们;您应该获得150K的矢量PDF.

Since you are on a Mac, you probably have Distiller. I'd give it a try — generate PS files as above, and then run them through Distiller; you should get a 150K vector PDF.

如果您坚持要进行栅格化,我建议将没有任何轴或标签的图形打印到tiff上,打开tiff,并在其顶部重新创建轴和标签.

If you insist on rasterizing, I can suggest printing the figure without any axes or labels to a tiff, opening the tiff, and recreating axes and labels on top of it.

这篇关于节省“繁重"在MATLAB中转换为PDF格式-渲染问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆