3

TikZ allows you to have shapes with gradients like this

\fill [
    left color=red,
    right color=blue,
] (0,0) circle

is the same possible for a plot line?

Something like

\addplot[very thick, smooth, left color=red, right color=blue] 

does not work.

2

1 Answer 1

8

You can use the mesh plot style and a colormap for this:

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[domain=0:360, enlargelimits=false]
    \addplot [
        mesh, % Use line segments instead of one unbroken line
        colormap={}{ % Define the colormap
            color(0cm)=(red);
            color(1cm)=(blue);
        },
        ultra thick,
        point meta=x % Define the value that's used to determine the color
    ] {sin(x)};
    \end{axis}
    \end{tikzpicture}
\end{document}

You must log in to answer this question.

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