I'm not sure this should be posted here, but I don't know where else to ask this question. Please feel free to refer to another more relevant SE if necessary.

I plotted a figure with Mathematica, and then saved it as a PDF. I enclosed it in my article, written in LaTeX. But the problem is that the image displayed has some weird coloring, which is not the original. See for yourself:

enter image description here enter image description here

The first image is how it should look like, the second one is how it does look like in my paper. (Those are a close up of the region of interest.) Note that this weird coloring also happens when I open the pdf image itself, and I tried different pdf viewers, and I also saw on my advisor's computer the same glitch, so I don't think the problem comes from LaTeX/my computer. Also, when I zoom in/out, the right coloring appears for some time (sometimes a few seconds, sometimes just a split moment), and then goes back to the weird yellow color.

Any idea?

Edit Minimal code that shows the problem:

As = Exp[3.089] 10^(-10);
ns = 0.96;
kstar = 0.05;
k0 = 0.008;
Ampk0 = As (k0/kstar)^(ns - 1);
ratiok = kstar/k0;
Nmax = 350;
fnlVala = 1;
PlotPts = 
  20 (*20 is quick but less nice, 60 takes times but looks good*); 

C2nl[nu_] := -((3^(3/2) 2^(3 nu - 1/2) Gamma[nu])/(
   4^nu \[Pi] BesselY[nu, 8/27]));

zetaL3[nu_, Ne_] := 3 Sqrt[Ampk0 (1 - Exp[-Ne (3 - 2 nu + ns - 1)])/(3 - 2 nu + ns - 1)]
deltar3[nu_, Ne_, fnl_] := Abs[(1 + 2^-3 (fnl C2nl[nu] (kstar/k0)^(nu - 3/2) zetaL3[nu, Ne])^2)/(1 + 2 fnl  C2nl[nu] (kstar/k0)^(nu - 3/2) zetaL3[nu, Ne]) - 1];
deltans3[nu_, fnl_, Ne_] := (3/2 - nu) fnl/ns C2nl[nu] (2 zetaL3[nu, Ne])/(1 + 2 fnl C2nl[nu] (kstar/k0)^(nu - 3/2) zetaL3[nu, Ne])

Mesh3 = ParametricPlot[{deltans3[x, fnlVala, y], 
    deltar3[x, y, fnlVala]}, {x, 1.46, 1.5}, {y, 0, Nmax}, 
   PlotStyle -> {{Blue,Opacity[0.3]}}, Mesh -> {39, 13}, 
   MeshStyle -> {{RGBColor[0., 0., 0.51], Opacity[0.5], Dotted}}, 
   PlotPoints -> PlotPts, AspectRatio -> 1, 
   Frame -> True,(*FrameLabel\[Rule]{ToExpression["n_s",TeXForm,
   RotateLabel -> False, LabelStyle -> Directive[Bold, 11], 
   PlotRange -> All, Axes -> False];


I think the problem is that Mathematica exports a very large PDF file, and the colored surfaces are actually a collection of small rectangles-ish, which I think is inefficient.

  • 2
    $\begingroup$ Please include the code/data that you used to generate the picture and export it to PDF. I don't think we would be able to help you otherwise. $\endgroup$
    – MarcoB
    Mar 16 '16 at 22:44
  • $\begingroup$ Could be a problem with the PDF viewer. What OS are you on, what Mathematica version, how do you invoke latex to create the PDF (pdflatex, xetex, via dvips, ...)? $\endgroup$
    – Jens
    Mar 17 '16 at 2:30
  • 2
    $\begingroup$ You might also want to look at these discussions, which may be relevant to your problem: (2629), (18625), and (644). $\endgroup$
    – MarcoB
    Mar 17 '16 at 3:55
  • $\begingroup$ I'm using Mathematica 10.2. I see the same problem both on the Preview and Skim viewers on MacOS 10.11. My friend, with a version of Windows 10, also see the same thing (I don't know what viewer he is using though). I don't think it is related to LaTeX (I use pdflatex) as when I open the PDF image by itself, I still see the same thing happening. @MarcoB, thanks, this is indeed useful, as it seems that I also have those weird polygons in my regions. $\endgroup$
    – AnSy
    Mar 17 '16 at 14:08

In this case, it seems that changing the background color to have opacity one solved the problem.

I think Mathematica is very poor at exporting vector graphics, and the generated file is much heavier than it should be. There were very good insights in the discussions provided in MarcoB's comment.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.