我想要一个光滑的1d 网格,用黑色曲线划线,但有颜色。我所能得到的只是下图所示的矩形集合……
\documentclass{standalone}
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\begin{document}\begin{tikzpicture}\begin{axis}
\addplot [mesh,line width=20pt,domain=-1:1,samples=101] {sin(360*x)*x};
\addplot [no marks,line width=20pt,domain=-1:1,samples=101] {sin(360*x)*x-1};
\end{axis}\end{tikzpicture}\end{document}
答案1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot [mesh, line width=20pt, samples at={-0.985,-0.965,...,1}, forget plot] {sin(360*x)*x};
\addplot [mesh, line width=20pt, samples at={-0.990,-0.970,...,1}, forget plot] {sin(360*x)*x};
\addplot [mesh, line width=20pt, samples at={-0.995,-0.975,...,1}, forget plot] {sin(360*x)*x};
\addplot [mesh, line width=20pt, samples at={-1.000,-0.980,...,1}] {sin(360*x)*x};
\addplot [no marks, line width=20pt, domain=-1:1, samples=101, smooth] {sin(360*x)*x-1};
\end{axis}
\end{tikzpicture}
\end{document}