同一轴上的两个图形 \addplot3 (pgfplots)

同一轴上的两个图形 \addplot3 (pgfplots)

我想使用 pgfplots 绘制两个图表。这是第一个: 在此处输入图片描述

\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}

,这是第二个: 在此处输入图片描述

\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}

当我尝试在同一个轴上绘制两个图形时,会发生以下情况

在此处输入图片描述

        \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}

也就是说,我的第二张图在零点附近与第一张图重叠。我怎样才能使第一张图在零点附近与第二张图重叠?很明显,如果我改变调用 \addplot3 的顺序,那么第一张图将与第二张图在任何地方重叠。我希望只在零点附近,这样图片看起来正确,类似于这样 在此处输入图片描述

TeX 文件

    \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

PGFPlots 没有延伸到各个图之外的 z 缓冲区,因此您需要按照正确的顺序绘制图。

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage{amsmath,amssymb}
\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))};
\addplot3[surf, domain=0:pi, y domain=-pi:0, samples=18, forget plot]{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}

两个表面图

编辑:使用不同的颜色和更好的线条接头。

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage{amsmath,amssymb}
\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$},
line join=bevel, point meta rel=per plot,
]
\addplot3[surf, domain=-pi:pi, samples=35, colormap/hot,  point meta min=-1, point meta max=1.5]{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, colormap/cool, point meta min=0, point meta max=2.5]{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=18, forget plot, colormap/hot, point meta min=-1,point meta max=1.5]{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}

两个表面图红色和蓝色

相关内容