如何在保持标签清晰的同时减小导出图的文件大小

Eli*_*sey 12 wolfram-mathematica

将相当复杂的图(特别是ListDensityPlot)导出为PDF或EPS(例如,用于发布)时,生成的文件大小可能非常大.例如:

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]
Run Code Online (Sandbox Code Playgroud)

Mathematica图形

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

如果我的实际数字是一个组合图,例如(编辑:f转到900),这将进一步复杂化

plot2 = Show[plot, Plot[x, {x, 500, 900}, PlotStyle -> Thick]]
Run Code Online (Sandbox Code Playgroud)

Mathematica图形

(或使用某些用法Epilog)我喜欢将背景ListDensityPlot光栅化,但保留其他标记并以"矢量"形式绘制.或者至少,帧标签是非光栅化的.

有没有办法做到这一点?

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


更新

我已经检查了相关的问题,但这需要比它需要的更复杂(主要是导出然后导入).我已经能够利用该问题中的一些技巧来分别从轴中提取图:

axes = Graphics[{}, Options[plot2]]
Run Code Online (Sandbox Code Playgroud)

Mathematica图形

plots = Graphics[plot2[[1]]]
Run Code Online (Sandbox Code Playgroud)

Mathematica图形

但是,在plots长期失去AspectRatioPlotRangeplots可以用被击中Rasterize,但它需要的尺寸固定.

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

小智 6

这正是我在这里编写链接函数的问题:http: //pages.uoregon.edu/noeckel/computernotes/Mathematica/listContourDensityPlot.html

它基于与Heike的答案相同的想法 - 我只是添加了一些功能,以便您可以安全地更改宽高比,不透明度,并与其他图表结合使用.在Heike的回答中看到我的评论.

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

plot = Show[
 listContourDensityPlot[data, 
  PlotRange -> {Automatic, Automatic, {0, 1}}, 
  InterpolationOrder -> 0, Contours -> None], 
 Graphics[Line[{{500, 500}, {700, 700}}]]]
Run Code Online (Sandbox Code Playgroud)

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

  • "AbsoluteOptions"目前有很多错误,技术支持承认错误. (2认同)
  • 是的,它需要对V9进行全面改造. (2认同)

Hei*_*ike 5

如果您正在处理2D绘图,则可以使用将光栅化绘图与矢量化轴组合Inset.例如

plot2 = ListDensityPlot[data, 
   PlotRange -> {Automatic, Automatic, {0, 1}}, 
   InterpolationOrder -> 0, Axes -> False, Frame -> False, 
   PlotRangePadding -> 0];

plotRange = PlotRange /. AbsoluteOptions[plot2, PlotRange];

plot = Graphics[{
  Inset[Image[plot2], plotRange[[All, 1]], {Left, Bottom}, Scaled[{.96, .96}]],
  Line[{{500, 500}, {700, 700}}]}, 
 Frame -> True, AspectRatio -> 1, 
 PlotRange -> plotRange, PlotRangePadding -> Scaled[.02]]

Export["test.pdf", plot]
Run Code Online (Sandbox Code Playgroud)

产生大约400 KB的.pdf.框架,刻度线和黑线仍然是矢量化的,因此在放大时它们会保持清晰:

图像的细节