How to decrease file size of exported plots while keeping labels sharp

血红的双手。 提交于 2019-12-03 03:17:59

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

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.

If you're dealing with 2D plots, you could combine a rasterized plot with vectorized axes by using Inset. For example

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]

produces a .pdf of about 400 KB. The frame, tick marks, and black line are still vectorized, so they stay sharp when zooming in:

If you are exporting as PDF, EPs or WMF, then the text should remain as vectors even if you have a rasterized component to the graphics.

I think the trick is to set the number of plot points to some low number in the ListDensityPlot command and then export as PDF as normal.

How about just plotting the function rather than making a list?

plot=DensityPlot[Exp[-(f - f0)^2/25^2], {f0, 500, 700}, {f, 300, 900}, 
 Epilog -> {Thick, Line[{{500, 500}, {700, 700}}]}, PlotPoints -> 50]

Export["test.pdf", plot]

file size 1.1MB

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!