我正在尝试使用 PGFplots 绘制波的表面,z = sin(x + y)。这是我的 MWE:
\documentclass{standalone}
\let\oldvec\vec
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepgfplotslibrary{patchplots}
\usepackage{comment}
\tikzset{>=latex} % for LaTeX arrow head
\usepackage{xcolor}
\pgfplotsset{colormap={wave}{rgb255(0cm)=(214,196,194); rgb255(1cm)=(183,166,158)}}
\providecommand{\sin}{} \renewcommand{\sin}{\hspace{2pt}\mathrm{sen}}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel=$x$,
ylabel=$t$,
small,
colormap/wave
]
% Onda
\addplot3[
surf,shader=interp,
domain=0:2*pi,
domain y=0:3*pi,
samples=50,
samples y=50,
]
(x , y , {sin((x - y)*360/pi)});
% Senoide do tempo
\addplot3[
thick,black,
domain=0:2*pi,
domain y=0:3*pi,
samples=10,
samples y=50,
]
(2*pi , y , {sin(-y*360/pi)});
% Senoide do comprimento
\addplot3[
thick,blue,
domain=0:2*pi,
domain y=0:3*pi,
samples=50,
samples y=10,
]
(x , 0 , {sin(x*360/pi)});
\end{axis}
\end{tikzpicture}
\end{document}
我有波面,还有两个正弦波来伴随边界,稍后我将在其中进行注释。
我的 z=0 上有一条奇怪的蓝线,一直沿着 x 轴。我不知道是什么原因造成的。有人知道吗?我盯着它看了将近一个小时左右,这让我发疯了。
此外,如果有人对如何制作“更清晰”的表面有任何建议,我将不胜感激!
答案1
因此,正如薛定谔的猫在评论中所说,问题在于samples y =10
,它必须变为 0。
我最终改变了很多情节,这是最终的结果:
% Adaptado de (BAUER, WESTFALL, DIAS, 2013, p.86, Figura 3.8)
% Adaptado de (BAUER, WESTFALL, 2014, p.466, Figure 15.8)
\documentclass{standalone}
\let\oldvec\vec
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{patchplots}
\usepackage{comment}
\tikzset{>=latex} % for LaTeX arrow head
\usepackage{xcolor}
\pgfplotsset{colormap={wave}{rgb255=(145,85,61) rgb255=(229,200,168) rgb255=(255,240,225) rgb255=(229,200,168) rgb255=(145,85,61)}}
\definecolor{length}{rgb}{0 , 0.5 , 0}
\definecolor{time}{rgb}{0 , 0 , 1}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={-45}{30},
width=12cm,
height=6cm,
xlabel=$x$,
ylabel=$t$,
zlabel=$z$,
zlabel style={rotate=-90},
zmin=-1,
zmax=1,
ticks=none,
grid=none,
colormap name=wave
]
% Senoide do comprimento
\addplot3[
very thick,black,
domain=0:720,
domain y=0:1080,
samples=70,
samples y=0,
]
(x , 1080 , {sin(-x)});
% Senoide do tempo
\addplot3[
very thick,black,
domain=0:720,
domain y=0:1080,
samples=70,
]
(720 , y , {sin(y)});
% Onda
\addplot3[
surf,shader=interp,
domain=0:720,
domain y=0:1080,
samples=70,
]
(x , y , {sin(y - x)});
% Senoide do tempo
\addplot3[
very thick,time,
domain=0:720,
domain y=0:1080,
samples=70,
]
(0 , y , {sin(y)});
% Senoide do comprimento
\addplot3[
very thick,length,
domain=0:720,
domain y=0:1080,
samples=70,
samples y=0,
]
(x , 0 , {sin(-x)});
% Indicação do período da onda
\draw[time,dashed] ( 0 , 90 , -1 ) -- (0 , 90 , 1);
\draw[time,dashed] ( 0 , 450 , -1 ) -- (0 , 450 , 1);
\draw[time, <->] ( 0 , 90 , 0 ) -- (0 , 450 , 0);
\draw (0 , 270 , 0) node[above]{\color{time}$\mathbf{T}$};
% Indicação do comprimento da onda
\draw[length,dashed] ( 270 , 0 , -1 ) -- ( 270 , 0 , 1);
\draw[length,dashed] ( 630 , 0 , -1 ) -- ( 630 , 0 , 1);
\draw[length, <->] ( 270 , 0 , 0 ) -- (630 , 0 , 0);
\draw (450 , 0 , 0) node[above]{\color{length}$\pmb{\lambda}$};
\end{axis}
\end{tikzpicture}
\end{document}
关于表面的锐度,也许可以在外层平面上添加黑色轮廓。我通过添加一个新图来实现这一点,这些平面非常厚且黑色,但我很确定我的代码不是最优雅或最精致的。