PGFPlots Conversion – How to Convert Mathematica Code to PGFPlots

pgfplotstikz-pgfwolfram-mathematica

I have a Mathematica code which I would like to convert into pgfplot only to obtain the contours so that I can use the 'TikZ' version with other drawings made using TikZ. I actually am not familiar with multivariate plotting that much in PGFPLOTS. The code is:

mycolor[z_] := RGBColor[1, 1 - z, 1 - z];
w0 = 0.1;
w[z_] := w0*Sqrt[1 + (z/0.25)^2];
i[r_, z_] := Sqrt[Exp[-(2*r^2)/(w[z]^2)]];
ContourPlot[i[r, z], {z, -1, 0}, {r, -1, 1}, PlotRange -> All,
PlotPoints -> 50, PlotTheme -> "Scientific",
ColorFunction -> mycolor, ColorFunctionScaling -> False,
Frame -> None, Contours -> 6]

The output is:

Output

UPDATE 1

I almost got what I wanted, but for some reasons those black lines don't appear.

\documentclass[border=3mm]{standalone}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    view={0}{90},
    colormap={custom}{color(0)=(white) color(1)=(red)},
    domain=-1:0,
    y domain=-1:1,
    axis line style={draw=none},
    ticks=none
]
\addplot3 [
contour filled={labels=false,number=6,draw color=black},samples=50
] {sqrt(exp((-2*y^2)/(0.1*sqrt(1 + (x/0.25)^2))^2))};
\end{axis}
\end{tikzpicture}
\end{document}

Output:

Output 2

UPDATE 2

If I use the feature of draw color of contour lua, I do get the lines I want, but they don't fit with the edges of contour filled one.

\documentclass[border=3mm]{standalone}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    view={0}{90},
    colormap={custom}{color(0)=(white) color(1)=(red)},
    domain=-1:0,
    y domain=-1:1,
    axis line style={draw=none},
    ticks=none,
]
\addplot3 [
contour filled={labels=false,number=6},samples=50
] {sqrt(exp((-2*y^2)/(0.1*sqrt(1 + (x/0.25)^2))^2))};
\addplot3 [
contour lua={labels=false,number=6,draw color=black},samples=50
] {sqrt(exp((-2*y^2)/(0.1*sqrt(1 + (x/0.25)^2))^2))};
\end{axis}
\end{tikzpicture}
\end{document}

output 3

Best Answer

I do not know what is going on with the different levels, but this looks like what you want:

\RequirePackage{luatex85}
\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={0}{90},
colormap={custom}{color(0)=(white) color(1)=(red)},
domain=-1:0, y domain=-1:1,
axis x line=none, axis y line=none,
]
\addplot3 [
contour filled={number=7},
samples=50,
] {sqrt(exp((-2*y^2)/(0.1*sqrt(1 + (x/0.25)^2))^2))};
\addplot3 [
contour lua={labels=false, levels={1/7,2/7,3/7,4/7,5/7,6/7}, draw color=black},
samples=100,
] {sqrt(exp((-2*y^2)/(0.1*sqrt(1 + (x/0.25)^2))^2))};
\end{axis}
\end{tikzpicture}
\end{document}

Wedge shape with different shades of red

Edit: From the manual:

/pgfplots/contour/number={⟨integer⟩} (initially 5) Configures the number of contour lines which should be produced by any contouring algorithm. The value is applied to both contour lua and contour filled.

It is apparently not treated in the same way for contour lua and contour filled. For contour filled, the domain is split evenly and for contour lua, the contours are placed, so that they are somehow evenly spaced. -hence the need to give the levels explicitly to match contour filled.