3

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,
]

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

%A-opt countour
\begin{axis}[%
view={0}{90},
shader=interp,
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,
]

\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\pgfmathresult{20}}]
{ln(2*y^(2)+x^(2))};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

My output is my output but it should be waiting output

I need some ideas to fix it.

Stefan Pinnow
  • 29,535
Katharina
  • 155
  • 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. –  Dec 21 '18 at 18:02
  • Thank you for advice, but the main problem is on the right plot, contour is wrong and area colors as well. – Katharina Dec 21 '18 at 18:11
  • The closest I could find in a quick search is this answer. –  Dec 21 '18 at 18:22
  • 3
    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
  • 3
    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
  • 2
    Do you want to write an self-answer, that is welcome here! – Mensch Dec 21 '18 at 21:42
  • 1
    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 05:53

1 Answers1

3

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: fixed pictire

Katharina
  • 155