# surface and contour plots of mathematical function

I have a problem with plotting contour plot with tikz. I have a mathematical function z=x^2+2*y^2 and I need to plot along log-axis as surface and contour. My code is

\documentclass[crop,tikz]{standalone}
\usepackage{tikz}
\usepackage{graphics}
\usepackage{pgfplots}
\usepackage{amsmath}
\begin{document}
\begin{figure}[hbt!]

\begin{tikzpicture}
\newcommand{\sample}{10}
\newcommand{\domain}{0.01:-4.6}
\newcommand{\kubesize}{6cm}
\begin{axis}[3d box=complete,
grid=major,
width=\kubesize,
height=\kubesize,
at={(1cm,18.5cm)},
scale = 1,
xlabel = {$\ln(\sigma_1)$},
xmin = ln(0.01), xmax = ln(0.99),
ylabel = {$\ln(\sigma_2)$},
ymin = ln(0.01), ymax =ln(0.99),
zlabel={$\ln(\Psi_A)$},
view/h=150,
]

surf,
samples=\sample,
domain=\domain,
y domain=\domain,
]
{ln(2*y^(2)+x^(2))};
\end{axis}

%A-opt countour
\begin{axis}[%
view={0}{90},
3d box=complete,
%grid=major,
width=\kubesize,
height=\kubesize,
at={(9cm,18.5cm)},
scale = 1,
xlabel = {$\ln(\sigma_1)$},
xmin = ln(0.01), xmax = ln(0.99),
ylabel = {$\ln(\sigma_2)$},
ymin = ln(0.01), ymax =ln(0.99),
zlabel={$\ln(\Psi_A)$},
view/h=-180,
]

surf,
samples=\sample,
domain=\domain,
y domain=\domain,
]
{ln(2*y^(2)+x^(2))};
\addplot3 [contour gnuplot = {number=14, labels={false}, draw color=black},
samples=\sample,z filter/.code={\def\pgfmathresult{20}}]
{ln(2*y^(2)+x^(2))};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}


My output is but it should be

I need some ideas to fix it.

• Welcome to TeX.SE! you can make the left plot "flatter" by adding unit vector ratio=1 1 0.5, to the options of the axis. Please note also that a figure environment makes only limited sense in a standalone document. – user121799 Dec 21 '18 at 18:02
• I found the mistake. It is only to change z filter/.code={\def\pgfmathresult{20}} to z filter/.code={\def\pgfmath result{20}}. – Katharina Dec 21 '18 at 20:03
• I'm voting to close this question as off-topic because the OP have found the mistake herself. – Sebastiano Dec 21 '18 at 21:10
• Do you want to write an self-answer, that is welcome here! – Mensch Dec 21 '18 at 21:42
• It is always better for every single future reader to find a question with its simple answer than a closed question with a hint to its solution in the comments. – Diaa Dec 22 '18 at 5:53

The solution of the problem is:

\documentclass[crop,tikz]{standalone}

\usepackage{tikz}


...

\begin{tikzpicture}


...

\addplot3[%
surf,
samples=\sample,
domain=\domain,
y domain=\domain,
]
{ln(2*y^(2)+x^(2))};

> \addplot3 [contour gnuplot = {number=14, labels={false}, draw
> color=black},
>     samples=\sample,z filter/.code={\def\pgfmath result{20}}]
>     {ln(2*y^(2)+x^(2))};

\end{axis}

\end{tikzpicture}

\end{figure}

\end{document}


My output is: