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:
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:
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}
Best Answer
I do not know what is going on with the different levels, but this looks like what you want:
Edit: From the manual:
It is apparently not treated in the same way for
contour lua
andcontour filled
. Forcontour filled
, the domain is split evenly and forcontour lua
, the contours are placed, so that they are somehow evenly spaced. -hence the need to give the levels explicitly to matchcontour filled
.