The VertexColors
that get introduced when a ColorFunction
is specified are not rendered smoothly in the exported PDF
- no matter what other options (such as Dashed
) you specify. So we really have two problems here. Bad color gradients along the line, and incorrect computation of the dash spacing.
If you don't care too much about the bad color gradients and just want a plot with an acceptable dashing, you could do something like this:
Show[#,
Graphics[{Thickness[.01], White, Dashing[{.02, .04}],
Cases[Normal@#[[1]], Line[_], Infinity]}]] &@
Plot[x^2, {x, -2, 2}, PlotStyle -> Thickness[.008],
ColorFunction -> Hue]
Here I have taken your original Plot
and initially removed the dashing. Before showing this plot, I extract from it the Line
that was produced, re-draw it a second time with dashing and slightly larger thickness at the background color (White
).
Finally, I place the dashed white line on top of the continuous colored line to get the appearance of a dashed colored line. For this to look correct in the exported PDF
, you have to play with the Dashing
and Thickness
manually.
The dashing in the export will look different from the notebook. In particular, the second number in Dashing[{0.02,0.04}]
must always be bigger than the first, or else you don't see anything!
Here is what the exported PDF
looks like with the above command:

If you do care about the bad color gradients in addition to the dashing, then I would suggest going with bitmap export right now because it would take a bitmap-based hack to get smooth color gradients in the PDF
anyway.
Export[...]
and withe theSave Graphics as...
menu option. $\endgroup$