5

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

RndColour is 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:

enter image description here

3
  • +1 for the image. I like it; altough I think you could easily finde more beautiful colors. Commented Jan 21, 2015 at 12:48
  • What is the smoothing function applied to the y-coordinates to get them to diverge from 0 as x increases and converge to 0 as x approaches 1? Commented Jan 21, 2015 at 12:53
  • @Thruston: the plots presented here are 50 non-intersecting brownian bridges. You should look into documentation about 'Dyson processes'. Here you start with a 50x50 zero matrix (t=0) and each entry then follows a brownian motion, under a harmonic field, while keeping for each t the matrix hermitian. What you then see plotted is the behaviour of the eigenvalues of the matrices, which are known to behave the same way as non intersecting brownian bridges. You also condition the matrix to end as a zero matrix, by substracting for each t a t*the final matrix. Commented Jan 21, 2015 at 14:15

1 Answer 1

5

I think what you need is a cycle list. Example from the manual

\documentclass{beamer} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[ stack plots=y,stack dir=minus, cycle list name=color list] \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \addplot coordinates {(0,1) (0.5,1) (1,1)}; \end{axis} \end{tikzpicture} \end{document} 

enter image description here

If you are not happy with the pre-defined color lists, you may define your own.

1
  • Thank you, this is working. The cycle list 'color list' is too small for my purposes, but as you suggested, I created one myself. Commented Jan 21, 2015 at 14:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.