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

前端 未结 4 1899
感情败类
感情败类 2021-02-05 18:52

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

4条回答
  •  天涯浪人
    2021-02-05 19:00

    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:

    detail of image

提交回复
热议问题