5
$\begingroup$

It has happened to me that when I export certain ContourPlot outputs, the colours in the legend appear different in the legend. See below the code and the two pictures (on the left the notebook file, on the right the exported pdf). What is happening?

ρ[x_, y_] := Sqrt[x^2 + y^2];
Θ[x_, y_] := ArcTan[x, y];

f[x_, y_, t_] := 
  Piecewise[{{1/2 + 
      0.000051502449550377714*t*BesselK[0, Sqrt[x^2 + y^2]/10] - 
      BesselK[0, 
        Sqrt[x^2 + y^2]/10]/(2*
         BesselK[0, 1/10]) + ((0.5 - 0.00012500000000000003*t)*
         BesselK[1, Sqrt[x^2 + y^2]/10]*Cos[0. + ArcTan[x, y]])/(2*
         BesselK[1, 1/10]), 
     x^2 + y^2 >= 
      1}, {((0.5 - 0.00012500000000000003*t)*
        BesselJ[1, Sqrt[x^2 + y^2]/10]*Cos[0. + ArcTan[x, y]])/(2*
        BesselJ[1, 1/10]), 0 < x^2 + y^2 < 1}}, 0];
g[x_, y_, t_] := 
  Piecewise[{{((0.5 - 0.0025000000000000005*t)*
        Sin[0. + ArcTan[x, y]])/(2*Sqrt[x^2 + y^2]), 
     x^2 + y^2 >= 
      1}, {((0.5 - 0.0025000000000000005*t)*Sqrt[x^2 + y^2]*
        Sin[0. + ArcTan[x, y]])/2, 0 < x^2 + y^2 < 1}}, 0];

x0=0;L=1;a=1;Ly=L;y0=0;

cs2[t_] :=  ContourPlot[(2 f[x, y, t]^2 + 
 2 g[ρ[x, y], Θ[x, y], t]^2)^(1/2), {x, -L + x0, L + x0}, {y, -L + y0, L + y0},    PlotLegends -> Automatic, PlotRange -> {Full, Full, {0, 0.5}},    PlotPoints -> 30,    ColorFunction -> ({Opacity[0.6],       ColorData["TemperatureMap"][#]} &), Contours -> 100,    RegionFunction -> Function[{x, y}, 0.01 < x^2  + y^2 < a^2],    Exclusions -> None];

Export["inner.pdf",cs2[0]]

enter image description hereenter image description here

$\endgroup$
7
  • 1
    $\begingroup$ What version are you using? When I run your code in either 10.3 or 11.0, I get this. Also, include your operating system, as that may be important for PDF exporting. You don't have y0 defined, but based on your plot range in the images I set it to the same value as x0. $\endgroup$
    – Jason B.
    Commented Aug 19, 2016 at 12:34
  • $\begingroup$ Also, what PDF viewer are you using? Can you upload a PDF? $\endgroup$
    – Szabolcs
    Commented Aug 19, 2016 at 12:35
  • $\begingroup$ I am on Mac OSX, and I have tried Skim and Preview, and both give the same colors. Version 10.0. $\endgroup$ Commented Aug 19, 2016 at 12:47
  • $\begingroup$ Can you reproduce the issue on a much simpler contour plot, like ContourPlot[Sin[x + y], {x, -3, 3}, {y, -3, 3}..... - it makes it easier to nail down what is happening if we can use a simpler example. Also, what happens if you use (Directive[Opacity[0.5], ColorData["TemperatureMap"][#]] &) for your ColorFunction instead? $\endgroup$
    – Jason B.
    Commented Aug 19, 2016 at 12:56
  • $\begingroup$ Same problem with this code: cs2 = ContourPlot[x + y^2, {x, -3, 3}, {y, -3, 3}, PlotLegends -> Automatic, PlotRange -> {Full, Full, {0, 0.5}}, PlotPoints -> 30, ColorFunction -> (Directive[Opacity[0.5], ColorData["TemperatureMap"][#]] &), Contours -> 100, RegionFunction -> Function[{x, y}, 0.01 < x^2 + y^2 < a^2], Exclusions -> None, ImageSize -> Large]; $\endgroup$ Commented Aug 19, 2016 at 13:06

0

Your Answer

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

Browse other questions tagged or ask your own question.