Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

1 Answer 1

up vote 8 down vote accepted

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

\pgfmathsetseed{1}
\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);
}
\end{tikzpicture}
}

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

 
discard

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.