8

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?

8

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.

  • 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 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.