2
$\begingroup$

I am trying to produce a 3D density plot from a set of points. Minimal code to generate a similar set of points and plot is

testData = RandomVariate[NormalDistribution[0, 1], {10000, 3}];
centers = Tuples[Range[-4, 4, 0.5], 3];
nf = Nearest[centers];
densityPlot = ListDensityPlot3D[KeyValueMap[Append, CountsBy[testData, 
    First@*nf]],
    OpacityFunction -> 0.025, ViewVertical -> {0, 0, 1}, 
    PlotLegends -> Automatic]

This produces output that looks exactly as I would like:

Mathematica's output of the densityPlot

But I need this to be exported to a PDF for inclusion in a LaTeX document. When I do so using

Export["densityPlot.pdf", densityPlot, "PDF"]

the ColorFunction appears to have been altered, and I get something like this:

PDF output of the densityPlot

How can I preserve the ColorFunction when exporting a ListDensityPlot3D?

$\endgroup$
  • 3
    $\begingroup$ I can reproduce this on macOS with Mathematica 12.0. It's a bug. You should contact Wolfram. I think that the simplest workaround is to use PNG instead of PDF. The end result is rasterized anyway. You would probably want to increase the ImageResolution during export. $\endgroup$ – Szabolcs Dec 15 '19 at 22:23