1

I found that the figure produced by \addplot[mesh] is composed of the line segments having the different colors.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        samples=50,
        point meta rel=axis wide,
        point meta=y,
        ]
    \addplot[mesh,thick] {sin(deg(x))};
    \end{axis}
\end{tikzpicture}
\end{document}

which produce enter image description here

The color transition is not smooth. I want to make the line color smooth and I rewrite the above code as

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{
compat=newest
}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        samples=50,
        point meta rel=axis wide,
        point meta=y,
        colormap access=direct,
        shader=interp
        ]
    \addplot[mesh,thick] {sin(deg(x))};
    \end{axis}
\end{tikzpicture}
\end{document}

That produces the line in the same color. How can make the line color varied according to the point meta and the color transition smooth?

Ice0cean
  • 1,646
  • 1
    What's wrong with increasing the number of samples? There's no need to increase it excessively if you just want the eye to perceive smooth variation of color. – Enlico Jun 28 '17 at 16:48
  • You might want to look at https://tex.stackexchange.com/a/137438/116936 – John Kormylo Jun 28 '17 at 16:49
  • The problem is, the shaders are meant for the facets of a surface, not for curves, or meshes. – marsupilam Jun 28 '17 at 17:43

1 Answers1

1

Do not try this at home ! (because it is silly ;)... !)

Seriously, you should just increase the samples number of your curve.

The output

enter image description here

The code

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}
      [
        samples=51,
        view={0}{0},
        ]
    \addplot3
    [
      surf,
      line width=2mm,
      point meta=z,
      shader=interp,
      samples y=2,
      y domain=0:.05,
    ]
      ({x-y*cos(deg(x)},0,{sin(deg(x))+y});
    \end{axis}
\end{tikzpicture}
\end{document}
marsupilam
  • 6,383
  • But what if I have a table with values instead of a function, so that I cannot simply increase the number of samples? – Scz Mar 09 '18 at 12:31
  • very late suggestion... but just use linear interpolation to add more samples to your table. – RTbecard Dec 22 '20 at 12:28