# How to draw gradient arrows with Tikz

I want to combine the two figures below into one. That is having an arrow with colors going from red at the bottom to blue at the top. Could anyone show me how to do it?

-
Could you please check whether Tikz: Shading a path without any filling helps you? –  Claudio Fiandrino Aug 25 '14 at 9:32
Thanks, could we assign colors to specific points on the path? I see only top and bottom color there. –  wererabit Aug 25 '14 at 9:53
I think you can easily do it by changing type of shading; if you look on the pgfmanual there is also a rainbow shading. –  Claudio Fiandrino Aug 25 '14 at 10:01
Please post a Minimum Working Example which produces the output you've posted (since you've already got that far). –  cfr Aug 25 '14 at 12:15

The problem with trying to do a "color-bar" style shading is that in the process of fitting a shading to a path PGF scales a shading so that only the center quarter of the shading is seen (see "Using Shadings" in the manual).

This means that either a color-bar has to be "squidged" into the center quarter of a shading definition, which is a pain to to manually, or the path to be shaded has to be clipped, and scaled manually which can also be a bit of a nuisance.

The following shows one way of specifying a color-bar with a list of named colors (assumed to occupy equal width of the bar) and automatically generate a (more-or-less) appropriate shading:

\documentclass[tikz, border=5]{standalone}
\usetikzlibrary{shapes.arrows}
\makeatletter
\pgfutil@tempcnta=0\relax
\ifnum\pgfutil@tempcnta=1\relax%
\edef\pgf@spec{color(0)=(#3);color(100)=(#3)}%
\else%
\pgfmathparse{50/(\pgfutil@tempcnta-1)}\let\pgf@step=\pgfmathresult%
%
\pgfutil@tempcntb=1\relax%
\pgfutil@for\pgf@tmp:={#3}\do{%
\ifnum\pgfutil@tempcntb=1\relax%
\edef\pgf@spec{color(0)=(\pgf@tmp);color(25)=(\pgf@tmp)}%
\else%
\ifnum\pgfutil@tempcntb<\pgfutil@tempcnta\relax%
\pgfmathparse{25+\pgf@step/4+(\pgfutil@tempcntb-1)*\pgf@step}%
\edef\pgf@spec{\pgf@spec;color(\pgfmathresult)=(\pgf@tmp)}%
\else%
\edef\pgf@spec{\pgf@spec;color(75)=(\pgf@tmp);color(100)=(\pgf@tmp)}%
\fi%
\fi%
}%
\fi%
}

\begin{document}
\begin{tikzpicture}[colorbar arrow/.style={
shape=double arrow,
shape border rotate=90,
minimum height=5cm,
}]
\node [colorbar arrow=shading1] at (0,0) {};
\node [colorbar arrow=shading2] at (1,0) {};
\node [colorbar arrow=shading3] at (2,0) {};
\end{tikzpicture}
\end{document}


-

An example with PSTricks. Run it with xelatex

\documentclass[pstricks,border=12pt,12pt]{standalone}