TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to draw a path/plot in TikZ whose shade depends on the coordinate. For example, I want say something like

\draw[color=black!\x] plot coordinates{ coord1 ... coord100};

i.e. the shade of the color depends on the coordinate of the point. In examples of using colour in TikZ documention that I found, the colour is set for the entire path, and does not change with the point. Is there a way to do what I want?

share|improve this question
up vote 8 down vote accepted

The manual contains also the following example (first page of Part VII):

\foreach \col in {black,red,green,blue}
\begin{tikzpicture}[x=10pt,y=10pt,ultra thick,baseline,line cap=round]
\coordinate (current point) at (0,0);
\coordinate (old velocity) at (0,0);
\coordinate (new velocity) at (rand,rand);
\foreach \i in {0,1,...,100}
\draw[\col!\i] (current point)
.. controls ++([scale=-1]old velocity) and
++(new velocity) .. ++(rand,rand)
coordinate (current point);
\coordinate (old velocity) at (new velocity);
\coordinate (new velocity) at (rand,rand);

This might give you an idea how to do it.

share|improve this answer
So, do \foreach on the coordinates, and the the drawing command like above. Thanks! – Boris Bukh Nov 9 '10 at 21:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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