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.

7

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.