# How to color a curve with many smooth transitioning colors [duplicate]

I want to "draw[]" a color line starting in green, ending in blue and a transition between green and blue in a smooth continuous fashion. For example in tikz/pgf plots we can use a command such as:

\shade[bottom color=gray, top color=green] (D)--(O)--(B);


to color a triangle with gray and green with a smooth (gradient) transition.

A more specific example is shown in this figure generated with gnuplot, but I do not want to plot a function, and I do not want axes. I just want to draw[] a line or an arc. In other words, I want to "shade[]" a curve in a rainbow coloring.

This is not a repeated question: I have seen these posts with similar questions: coloring edge segments with different colors

That is not what I want.

Is there a function in TikZ or PGS (no pstricks or metapost please) that do this?

Thanks.

Update:

Here is my poor man solution:

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.11}

\begin{document}

\begin{tikzpicture}
\coordinate (O) at (0,0);
\foreach \t in {0.,0.01,...,1}
{
\coordinate (A) at (\t, \t);
\def\scl{20}
\pgfmathsetmacro\s{\scl*\t}
\draw[color=blue!\s!green]  (A) circle (0.1mm);

}

\end{tikzpicture}

\end{document}


and here the plot:

The main problem here is that the curve is hard coded. So, for another curve, I would need a new code.

I will work on creating a macro for a general path. Any ideas? Thanks.

## marked as duplicate by OSjerick, Kurt, user13907, Werner, Paul Gaborit tikz-pgf StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Nov 21 '15 at 7:46

Section 4.7.6 of the pgfplots documentation shows how to define your own colormap, but you need to take slightly different approaches to apply the map to symbols or lines.

\documentclass[border=1mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[colormap={greenblue}{rgb255(0cm)=(0,0,255); rgb255(1cm)=(0,255,0)}]