单独移动 z 标签会导致 pgfplots 出现错误

单独移动 z 标签会导致 pgfplots 出现错误

如果我将垂直蓝色平面添加到此 tikzpicture,我将失去单独移动 z 刻度标签的能力,即我收到错误

Undefined control sequence.
<argument> (\tick
                  == -1)*0.1em

所以我必须注释掉用于移动 z 刻度标签的代码,因为这样会导致重叠。

奇怪的是,如果我注释掉显示飞机的代码:

\addplot[fill = blue, opacity = 0.4, samples = 2] fill between [of = top and bottom];

然后我就可以毫无问题地移动 z 刻度标签了。有什么建议可以解决这个问题吗?

这是完整代码

\documentclass{article}
\usepackage{pgfplots}
\usepackage[italian]{babel}
\usepgfplotslibrary{fillbetween}
\usepackage[applemac]{inputenc}
\newcommand{\fonts}[1]{\fontsize{#1pt}{#1pt}\selectfont}
\begin{document}
\begin{center}
\begin{tikzpicture}
% tick label font and positioning
\pgfplotsset{
% x labels
every x tick label/.append style = {font = \fonts{11}, 
xshift = {(\tick == -6.28)* 0.04em},    yshift = {(\tick == -6.28)*0.3em},
xshift = {(\tick == -3.14)*-0.38em},    yshift = {(\tick == -3.14)*0.4em},
xshift = {(\tick == 0)*-0.28em},        yshift = {(\tick == 0)*0.25em},
xshift = {(\tick == 3.14)*-0.28em},     yshift = {(\tick == 3.14)*0.25em},
xshift = {(\tick == 6.28)*-0.26em},     yshift = {(\tick == 6.28)*0.34em}},
% y labels
every y tick label/.append style = {font = \fonts{11}, 
xshift = {(\tick == -6.28)*0.35em},     yshift = {(\tick == -6.28)*1em}, 
xshift = {(\tick == -3.14)*0.22em},     yshift = {(\tick == -3.14)*0.76em}, 
xshift = {(\tick == 0)*0.28em},         yshift = {(\tick == 0)*0.45em}, 
xshift = {(\tick == 3.14)*0.28em},      yshift = {(\tick == 3.14)*0.45em}, 
xshift = {(\tick == 6.28)*0.25em},      yshift = {(\tick == 6.28)*0.56em}}}
% z labels
%every z tick label/.style = {font = \fonts{11}, 
%xshift = {(\tick == -1)*0.1em},        yshift = {(\tick == -1)*0.5em}, 
%xshift = {(\tick == 0)*0.1em},     yshift = {(\tick == 0)*0.15em}, 
%xshift = {(\tick == 1)*0.1em},         yshift = {(\tick == 1)*0.1em}}}
% axis
\begin{axis}[
xlabel = $x$, ylabel = $y$, width = 10cm, view={30}{60}, 
ymin = -2*pi, ymax = 2*pi,
zmin = -1, zmax = 1, 
xtick = {-6.28, -3.14,..., 6.28}, 
ytick = {-6.28, -3.14,..., 6.28}, 
xticklabels = {$-2\pi$, $-\pi$, $0$, $\pi$, $2\pi$}, 
yticklabels = {$-2\pi$, $-\pi$, $0$, $\pi$, $2\pi$}]
% plot (samples = 65)
\addplot3[surf, samples = 5, domain = -2*pi:2*pi, y domain = -pi:2*pi, opacity = 0.5] {sin(deg(x))*cos(deg(y))};
\addplot3[domain = -2*pi:2*pi, fill = blue, opacity = 0.1, name path = top] (x, -pi, 1);
\addplot3[domain = -2*pi:2*pi, fill = blue, opacity = 0.1, name path = bottom] (x, -pi, -1);
\addplot3[fill = blue, opacity = 0.4, samples = 2] fill between [of = top and bottom];
\addplot3[domain = -2*pi:2*pi, line width = 1, samples=60, samples y = 0] ({x}, {-pi}, {-sin(deg(x))});
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

答案1

在等待解释(我无法给出)时,我可以提供一个解决方法:

\addplot3[fill = blue, opacity = 0.4] coordinates {(-6.28,-3.14,-1)(6.28,-3.14,-1)(6.28,-3.14,1)(-6.28,-3.14,1)(-6.28,-3.14,-1)};

因此肯定比使用不太方便fill between,但它确实有效。

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\usepackage[italian]{babel}
\usepgfplotslibrary{fillbetween}
\usepackage[applemac]{inputenc}
\newcommand{\fonts}[1]{\fontsize{#1pt}{#1pt}\selectfont}
\begin{document}
% \begin{center}
\begin{tikzpicture}
% tick label font and positioning
\pgfplotsset{
% x labels
every x tick label/.append style = {font = \fonts{11}, 
xshift = {(\tick == -6.28)* 0.04em},    yshift = {(\tick == -6.28)*0.3em},
xshift = {(\tick == -3.14)*-0.38em},    yshift = {(\tick == -3.14)*0.4em},
xshift = {(\tick == 0)*-0.28em},        yshift = {(\tick == 0)*0.25em},
xshift = {(\tick == 3.14)*-0.28em},     yshift = {(\tick == 3.14)*0.25em},
xshift = {(\tick == 6.28)*-0.26em},     yshift = {(\tick == 6.28)*0.34em}},
% y labels
every y tick label/.append style = {font = \fonts{11}, 
xshift = {(\tick == -6.28)*0.35em},     yshift = {(\tick == -6.28)*1em}, 
xshift = {(\tick == -3.14)*0.22em},     yshift = {(\tick == -3.14)*0.76em}, 
xshift = {(\tick == 0)*0.28em},         yshift = {(\tick == 0)*0.45em}, 
xshift = {(\tick == 3.14)*0.28em},      yshift = {(\tick == 3.14)*0.45em}, 
xshift = {(\tick == 6.28)*0.25em},      yshift = {(\tick == 6.28)*0.56em}},
% z labels
every z tick label/.style = {font = \fonts{11}, 
xshift = {(\tick == -1)*0.1em},        yshift = {(\tick == -1)*0.5em}, 
xshift = {(\tick == 0)*0.1em},     yshift = {(\tick == 0)*0.15em}, 
xshift = {(\tick == 1)*0.1em},         yshift = {(\tick == 1)*0.1em}}
}
% axis
\begin{axis}[
xlabel = $x$, ylabel = $y$, width = 10cm, view={30}{60}, 
ymin = -2*pi, ymax = 2*pi,
zmin = -1, zmax = 1, 
xtick = {-6.28, -3.14,..., 6.28}, 
ytick = {-6.28, -3.14,..., 6.28}, 
xticklabels = {$-2\pi$, $-\pi$, $0$, $\pi$, $2\pi$}, 
yticklabels = {$-2\pi$, $-\pi$, $0$, $\pi$, $2\pi$}]
% plot (samples = 65)
\addplot3[surf, samples = 5, domain = -2*pi:2*pi, y domain = -pi:2*pi, opacity = 0.5] {sin(deg(x))*cos(deg(y))};
\addplot3[domain = -2*pi:2*pi, fill = blue, opacity = 0.1, name path = top] (x, -pi, 1);
\addplot3[domain = -2*pi:2*pi, fill = blue, opacity = 0.1, name path = bottom] (x, -pi, -1);
\addplot3[fill = blue, opacity = 0.4] coordinates {(-6.28,-3.14,-1)(6.28,-3.14,-1)(6.28,-3.14,1)(-6.28,-3.14,1)(-6.28,-3.14,-1)};
\addplot3[domain = -2*pi:2*pi, line width = 1, samples=60, samples y = 0] ({x}, {-pi}, {-sin(deg(x))});
\end{axis}
\end{tikzpicture}
% \end{center}
\end{document}

相关内容