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…

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

enter image description here

1 Answer 1

\documentclass[tikz, border=1cm]{standalone}
  \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};

Graph with smooth colored and black curve

  • 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 .