如何在保持标签清晰的同时减小导出图的文件大小 [英] How to decrease file size of exported plots while keeping labels sharp

查看:19
本文介绍了如何在保持标签清晰的同时减小导出图的文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当将相当复杂的图(尤其是 ListDensityPlot)导出为 PDF 或 EPS(例如用于出版)时,生成的文件可能会非常大.例如:

When exporting rather complicated plots (especially ListDensityPlot) as a PDF or EPS (for publication, for example), the resulting file size can be quite large. For example:

data = Flatten[Table[{f0, f, Exp[-(f - f0)^2/25^2]}, {f0, 500, 700, 5}, {f, 300, 
 900}], 1];
plot=ListDensityPlot[data,PlotRange->{Automatic,Automatic,{0,1}},InterpolationOrder->0]

此示例数据集的大小与我通常使用的大小相同.当我使用 Export["C:\\test.pdf", plot] 导出时,它会生成一个大小为 23.9MB 的 PDF 文件.如果我改为尝试 Export["C:\\test1.pdf", Rasterize[plot]] 它要小得多,但图像的完整性和可缩放性自然会受到影响.

This example data set is on the order of the size I typically work with. When I export using Export["C:\\test.pdf", plot], it generates a PDF file 23.9MB in size. If I instead try Export["C:\\test1.pdf", Rasterize[plot]] it is far smaller, but the integrity and rescalability of the image naturally suffers.

如果我的实际图形是一个组合图,这会进一步复杂化,例如 (Edit: f going to 900)

This is complicated further if my actual figure is a combined plot, such as (Edit: f goes to 900)

plot2 = Show[plot, Plot[x, {x, 500, 900}, PlotStyle -> Thick]]

(或使用 Epilog),我希望将背景 ListDensityPlot 栅格化,但将其他标记和绘图保留在vector"中' 形式.或者至少,框架标签是非光栅化的.

(or with some usage of Epilog) where I'd love to have the background ListDensityPlot be rasterized, but keep the other markup and plots in ``vector'' form. Or at the very least, the frame labels be non-rasterized.

有没有办法做到这一点?

Is there any way to do this?

或者,通过其他一些聪明的方法来实现相同的目标?

Or, to accomplish the same goal via some other clever method?

我已经查看了相关问题,但这一定比它需要的复杂得多(基本上是导出然后导入).我已经能够利用该问题中的一些技巧从轴中单独提取绘图:

I've checked out the related question, but that's gotta be way more complicated than it needs to be (essentially exporting then importing). I've been able to utilize some of the tricks in that question to extract the plot separately from the axes:

axes = Graphics[{}, Options[plot2]]

plots = Graphics[plot2[[1]]]

但是,plots 术语失去了 AspectRatioPlotRange 等.plots 可以用光栅化,但需要尺寸修正.

But, the plots term loses the AspectRatio and PlotRange, etc. plots can be hit with a Rasterize, but it needs dimensional fixing.

然后,如何将它们组合在一起?

And then, how to combine them together?

推荐答案

这正是我编写链接到此处的函数所针对的那种问题:http://pages.uoregon.edu/noeckel/computernotes/Mathematica/listContourDensityPlot.html

This is exactly the kind of problem for which I wrote the function linked here: http://pages.uoregon.edu/noeckel/computernotes/Mathematica/listContourDensityPlot.html

它基于与 Heike 的回答相同的想法——我只是添加了更多功能,以便您可以安全地更改纵横比、不透明度并与其他绘图结合.在 Heike 的回答中查看我的评论.

It's based on the same idea as in Heike's answer -- I just added some more features so that you can safely change the aspect ratio, opacity, and combine with other plots. See my comment in Heike's answer.

要尝试使用您的数据,请执行以下操作:

To try it with your data, do something like this:

plot = Show[
 listContourDensityPlot[data, 
  PlotRange -> {Automatic, Automatic, {0, 1}}, 
  InterpolationOrder -> 0, Contours -> None], 
 Graphics[Line[{{500, 500}, {700, 700}}]]]

从父页面也链接了几个类似的功能.

There are a couple of similar functions linked from the parent page, too.

这篇关于如何在保持标签清晰的同时减小导出图的文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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