3

I'd like a smooth 1d mesh, line the black curve, but coloured. All I'm able to get is the collection of rectangles shown in the figure below…

\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}

enter image description here

1 Answer 1

3
\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}

Graph with smooth colored and black curve

1
  • Nice hack! You basically overlaid 4 plots using offset samplings.
    – Atcold
    Nov 15, 2022 at 17:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .