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.


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



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

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.