Two graphs in the same axes \addplot3 (pgfplots)

1.6k views Asked by At

I want to draw two graphs using pgfplots. Here's the first one:

enter image description here

\begin{tikzpicture}
     \begin{axis}[
        xmin=-pi,
        xmax=pi,
        ymin=-pi,
        ymax=pi,
        zmin=0,
        zmax=2.5,
        xlabel={$\varkappa_x$},
        ylabel={$\varkappa_y$},
        zlabel={$\omega$},
        xtick={-pi,-pi/2,0,pi/2,pi},
        xticklabels={$-\pi$,$-\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$,$\pi$},
        ytick={-pi,-pi/2,0,pi/2,pi},
        yticklabels={$-\pi$,$-\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$,$\pi$}
        ]
        \addplot3[surf,domain=-pi:pi,samples=40]{sqrt(2*sin(deg((x+y)/2))^2+sin(deg(x/2))^2+sin(deg(y/2))^2-sqrt(4*sin(deg((x+y)/2))^4+(sin(deg(x/2))^2-sin(deg(y/2))^2)^2))};
     \end{axis}
  \end{tikzpicture}

,

here's the second one:

enter image description here

\begin{tikzpicture}
     \begin{axis}[
        xmin=-pi,
        xmax=pi,
        ymin=-pi,
        ymax=pi,
        zmin=0,
        zmax=2.5,
        xlabel={$\varkappa_x$},
        ylabel={$\varkappa_y$},
        zlabel={$\omega$},
        xtick={-pi,-pi/2,0,pi/2,pi},
        xticklabels={$-\pi$,$-\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$,$\pi$},
        ytick={-pi,-pi/2,0,pi/2,pi},
        yticklabels={$-\pi$,$-\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$,$\pi$}
        ]
        \addplot3[surf,domain=-pi:pi,samples=40]{sqrt(2*sin(deg((x+y)/2))^2+sin(deg(x/2))^2+sin(deg(y/2))^2+sqrt(4*sin(deg((x+y)/2))^4+(sin(deg(x/2))^2-sin(deg(y/2))^2)^2))};
     \end{axis}
  \end{tikzpicture}

.

When I try to plot both graphs in the same axes, this is what happens

https://i.stack.imgur.com/susry.png

\begin{tikzpicture}
     \begin{axis}[
        xmin=-pi,
        xmax=pi,
        ymin=-pi,
        ymax=pi,
        zmin=0,
        zmax=2.5,
        xlabel={$\varkappa_x$},
        ylabel={$\varkappa_y$},
        zlabel={$\omega$},
        xtick={-pi,-pi/2,0,pi/2,pi},
        xticklabels={$-\pi$,$-\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$,$\pi$},
        ytick={-pi,-pi/2,0,pi/2,pi},
        yticklabels={$-\pi$,$-\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$,$\pi$}
        ]
        \addplot3[surf,domain=-pi:pi,samples=40]{sqrt(2*sin(deg((x+y)/2))^2+sin(deg(x/2))^2+sin(deg(y/2))^2-sqrt(4*sin(deg((x+y)/2))^4+(sin(deg(x/2))^2-sin(deg(y/2))^2)^2))};
        \addplot3[surf,domain=-pi:pi,samples=40]{sqrt(2*sin(deg((x+y)/2))^2+sin(deg(x/2))^2+sin(deg(y/2))^2+sqrt(4*sin(deg((x+y)/2))^4+(sin(deg(x/2))^2-sin(deg(y/2))^2)^2))};
     \end{axis}
  \end{tikzpicture}

,

that is, my second graph overlaps the first one in the vicinity of zero. How can I make the first graph in the vicinity of zero overlap with the second one? It is clear that if I change the sequence of calling \addplot3, then the first graph will overlap with the second one everywhere. I would like only in the vicinity of zero, so that the picture looks correct similar as this

enter image description here

TEX file

\documentclass{standalone}

\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{amsmath,amssymb}
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english, russian]{babel}


\pgfplotsset{compat=1.9}

\begin{document}
            \begin{tikzpicture}
                \begin{axis}[
                    xmin=-pi,
                    xmax=pi,
                    ymin=-pi,
                    ymax=pi,
                    zmin=0,
                    zmax=2.5,
                    xlabel={$\varkappa_x$},
                    ylabel={$\varkappa_y$},
                    zlabel={$\omega$},
                    xtick={-pi,-pi/2,0,pi/2,pi},
                    xticklabels={$-\pi$,$-\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$,$\pi$},
                    ytick={-pi,-pi/2,0,pi/2,pi},
                    yticklabels={$-\pi$,$-\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$,$\pi$}
                    ]
                    \addplot3[surf,domain=-pi:pi,samples=35]{sqrt(2*sin(deg((x+y)/2))^2+sin(deg(x/2))^2+sin(deg(y/2))^2-sqrt(4*sin(deg((x+y)/2))^4+(sin(deg(x/2))^2-sin(deg(y/2))^2)^2))};
                    \addplot3[surf,domain=-pi:pi,samples=35]{sqrt(2*sin(deg((x+y)/2))^2+sin(deg(x/2))^2+sin(deg(y/2))^2+sqrt(4*sin(deg((x+y)/2))^4+(sin(deg(x/2))^2-sin(deg(y/2))^2)^2))};
                \end{axis}
        \end{tikzpicture}
\end{document}
1

There are 1 answers

2
samcarter_is_at_topanswers.xyz On BEST ANSWER

You can redraw parts of your first function:

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
     \begin{axis}[
        xmin=-pi,
        xmax=pi,
        ymin=-pi,
        ymax=pi,
        zmin=0,
        zmax=2.5,
        xlabel={$\kappa_x$},
        ylabel={$\kappa_y$},
        zlabel={$\omega$},
        xtick={-pi,-pi/2,0,pi/2,pi},
        xticklabels={$-\pi$,$-\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$,$\pi$},
        ytick={-pi,-pi/2,0,pi/2,pi},
        yticklabels={$-\pi$,$-\frac{\pi}{2}$,$0$,$\frac{\pi}{2}$,$\pi$}
        ]
        \addplot3[surf,domain=-pi:pi,samples=40]{sqrt(2*sin(deg((x+y)/2))^2+sin(deg(x/2))^2+sin(deg(y/2))^2-sqrt(4*sin(deg((x+y)/2))^4+(sin(deg(x/2))^2-sin(deg(y/2))^2)^2))};
        \addplot3[surf,domain=-pi:pi,samples=40]{sqrt(2*sin(deg((x+y)/2))^2+sin(deg(x/2))^2+sin(deg(y/2))^2+sqrt(4*sin(deg((x+y)/2))^4+(sin(deg(x/2))^2-sin(deg(y/2))^2)^2))};
        \addplot3[
          surf,
          domain=0:pi, 
          y domain=-pi:0,
          samples=20,
        ]{sqrt(2*sin(deg((x+y)/2))^2+sin(deg(x/2))^2+sin(deg(y/2))^2-sqrt(4*sin(deg((x+y)/2))^4+(sin(deg(x/2))^2-sin(deg(y/2))^2)^2))};        
     \end{axis}
  \end{tikzpicture}

\end{document}

enter image description here