我正在使用繪製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}