How to get production-quality vector graphic exported from Mathematica that looks like what is plotted in Mathematica. Example code:

plt = DensityPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}];
Export["C:\\test.pdf", plt, "AllowRasterization" -> False (*This is important*)];

What image plt looks like in Mathematica: What image plt looks like in Mathematica

What pdf export of plt looks like
enter image description here

which no longer has the color interpolation, but is tessellated. I've looked around a bit, and can't seem to find an answer. Any solutions?

Ps. Setting "AllowRasterization" -> True makes the file 9 MB, since It renders all the little tets; otherwise, the file is 0.1 MB in pure vector form.

  • $\begingroup$ rasterizeBackground might be helpful. $\endgroup$
    – corey979
    Commented Jan 29, 2018 at 6:20
  • $\begingroup$ Hm. I use Mathematica version 11.0.1 on macos 10.13.3 and to my own supprise, it seems to work with Export["test.pdf", plt];. Indeed, Mathematica does not rasterize on export, but it also cannot reimport the result. The resulting PDF is about 533 KB large and renders a bit slow and buggy in Preview. "AllowRasterization" -> True leads ot a 66 KB pdf. Note also that the image you posted does not coincide with plt. $\endgroup$ Commented Jan 29, 2018 at 7:37
  • 1
    $\begingroup$ You could use the function contourDensityPlot described in my answer to Saner alternative to ContourPlot fill. This is probably a duplicate of that question. $\endgroup$
    – Jens
    Commented Aug 9, 2018 at 15:43


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.