我正在使用绘制surf
3d 图。该表面需要投影到平面上,这可以通过添加另一个图来实现。Tikz/Pgf
gnuplot
surf
问题是,surf
尽管使用了
shader=interp
一种可能性是增加数量,samples
但是构建变得缓慢,我无法超过 75 个样本。
接下来是示例代码
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{tikzpicture}
\begin{axis} [width=\textwidth,
height=\textwidth,
ultra thick,
colorbar,
colorbar style={yticklabel style={text width=2.5em,
align=right,
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1,
},
},
xlabel={$\rho_x=k_xr_x$},
ylabel={$\rho_y=k_yr_y$},
zlabel={$j_l(\rho)$},
3d box,
zmax=2.5,
xmin=-3, xmax=3,
ymin=-3.1, ymax=3.1,
ytick={-3, -2, ..., 3},
grid=major,
grid style={line width=.1pt, draw=gray!30, dashed},
x tick label style={/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1
},
y tick label style={/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1
},
z tick label style={/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1
},
]
\addplot3[surf,
shader=interp,
mesh/ordering=y varies,
domain=-3:3,
y domain=-3.1:3.1,
]
gnuplot {besj0(x**2+y**2)};
\addplot3[surf,
samples=51,
shader=interp,
mesh/ordering=y varies,
domain=-3:3,
y domain=-3.1:3.1,
point meta=rawz,
z filter/.code={\def\pgfmathresult{2.5}},
]
gnuplot {besj0(x**2+y**2)};
\end{axis}
\end{tikzpicture}
\end{document}
这段代码的运行结果如下图所示
关于如何使颜色之间的过渡更加平滑,您有什么想法吗?
答案1
如果您主要关注的是颜色过渡,那么您可能需要使用极坐标图,因为该函数仅取决于半径而不是角度。然后,您可以增加径向的样本,同时保持角度方向的样本相对较小。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{tikzpicture}
\begin{axis} [width=\textwidth,
height=\textwidth,
ultra thick,
colorbar,
colorbar style={yticklabel style={text width=2.5em,
align=right,
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1,
},
},
xlabel={$\rho_x=k_xr_x$},
ylabel={$\rho_y=k_yr_y$},
zlabel={$j_l(\rho)$},
3d box,
zmax=2.5,
xmin=-3, xmax=3,
ymin=-3.1, ymax=3.1,
ytick={-3, -2, ..., 3},
grid=major,
grid style={line width=.1pt, draw=gray!30, dashed},
x tick label style={/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1
},
y tick label style={/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1
},
z tick label style={/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1
},
data cs=polar,
]
\addplot3[surf, samples=37,samples y=101,
shader=interp,
z buffer=sort,
%mesh/ordering=y varies,
domain=0:360,
y domain=3.1:0,
]
gnuplot {besj0(y**2)};
\addplot3[surf, samples=36, samples y=101,
shader=interp,
%mesh/ordering=y varies,
domain=0:360,
y domain=0:3.1,
point meta=rawz,
z filter/.code={\def\pgfmathresult{2.5}},
]
gnuplot {besj0(y**2)};
\end{axis}
\end{tikzpicture}
\end{document}
作为“副作用”,摆动也会消失,因为它们是在笛卡尔坐标中绘制旋转对称函数的结果。
这是笛卡尔图和极坐标图的组合。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{tikzpicture}
\begin{axis} [width=\textwidth,
height=\textwidth,
ultra thick,
colorbar,
colorbar style={yticklabel style={text width=2.5em,
align=right,
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1,
},
},
xlabel={$\rho_x=k_xr_x$},
ylabel={$\rho_y=k_yr_y$},
zlabel={$j_l(\rho)$},
3d box,
zmax=2.5,
xmin=-3, xmax=3,
ymin=-3.1, ymax=3.1,
ytick={-3, -2, ..., 3},
grid=major,
grid style={line width=.1pt, draw=gray!30, dashed},
x tick label style={/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1
},
y tick label style={/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1
},
z tick label style={/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=1
},
]
\addplot3[surf, samples=75,
shader=interp,
mesh/ordering=y varies,
domain=-3:3,
y domain=-3.1:3.1,
]
gnuplot {besj0(x**2+y**2)};
\addplot3[surf, samples=36, samples y=101,
shader=interp,
%mesh/ordering=y varies,
domain=0:360,
y domain=0:3.1,
point meta=rawz,
data cs=polar,
z filter/.code={\def\pgfmathresult{2.5}},
]
gnuplot {besj0(y**2)};
\end{axis}
\end{tikzpicture}
\end{document}