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


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