I want to plot lots of (50, to be precise) function (Brownian motions, if you want to know) in one TikZ axis environment, with each line with a different randomly chosen color.
I achieved to do it, but I'm very unhappy with the way I did it, and I bet there is a more efficient/beautiful/neat way of doing it. The idea of my solution was to use Matlab in order to create a random colormap, with lots of colors involved. But this makes me writing a huge amount of stuff which, I'm sure, can be done more easily.
This is the code I used, here with 3 files for the sake of simplicity.
\documentclass{beamer} \usepackage{pgfplots} \begin{filecontents*}{file1.plot} 0 0 1 1 2 2 3 1 4 0 \end{filecontents*} \begin{filecontents*}{file2.plot} 0 1 1 3 2 5 3 3 4 1 \end{filecontents*} \begin{filecontents*}{file3.plot} 0 2 1 5 2 7 3 5 4 2 \end{filecontents*} \begin{document} \frame{ \begin{tikzpicture}[scale=.8] \pgfplotsset{/pgfplots/colormap={rndcm}{rgb255=(204,41,26)rgb255=(74,148,66)rgb255=(66,127,234)rgb255=(85,47,111)rgb255=(112,36,137)rgb255=(6,175,58)rgb255=(5,47,165)rgb255=(164,174,225)rgb255=(86,138,183)rgb255=(203,114,174)rgb255=(219,140,254)rgb255=(183,141,85)rgb255=(239,188,220)rgb255=(160,68,52)rgb255=(178,143,23)rgb255=(131,96,248)rgb255=(25,70,14)rgb255=(6,49,203)rgb255=(75,128,101)rgb255=(22,54,42)} } \begin{axis} \foreach \j in {1,2,3} { \addplot [no markers, point meta=explicit, mesh] table [meta expr=\j] {file\j.plot}; } \end{axis} \end{tikzpicture} } \end{document} I tried to put
\pgfmathparse{rnd} \xdefinecolor{RndColour}{hsb}{\pgfmathresult, 1, 1} \addplot [no markers, point meta=explicit, color = RndColour] table [meta expr=\j] {file\j.plot}; within the \foreach loop, but it complains, saying that
RndColouris undefined
(Note that I can define the random colour that way outside the foreach loop, but then every lines are in the same colour.)
So, the question is: is it a way to do what I want with a better code than mine? I guess the answer is 'yes'. So, the actual question is: how to do it?
For the record, what I get with my heavy canon solution is this, and it looks pretty much the way I want it:

