I want to make a plot that shows the density of trajectories (x-y plots). In other words I want a plot that's analogous to this but with curves instead of points as data.
enter image description here

Here's what I'm doing right now (with a simplified function) which gives okay results for 100 curves but doesn't scale to 10,000:

ta = RandomVariate[NormalDistribution[0, 0.3], {100}];
p = Map[Cos[t - #] &, ta];
Plot[p, {t, 0, 10}, PlotStyle -> {{Black, Opacity[0.05]}}]

enter image description here

I'd also prefer to not have to quantize the x-y space. But if that's the only solution I'll accept it.

  • 1
    $\begingroup$ Have you seen DensityPlot, could you use that to display the number of trajectories that pass through the X-Y space? $\endgroup$ Jun 27, 2015 at 0:07
  • $\begingroup$ I have. I'm not sure how i'd compute a density function from 10,000 stochastic trajectories though... $\endgroup$ Jun 27, 2015 at 5:17
  • $\begingroup$ At each of may constant-x surfaces, compute the distribution (in y) of lines that pass through it. Of course, this will require discretizing x-y space. $\endgroup$
    – bbgodfrey
    Jun 27, 2015 at 6:29

1 Answer 1


Here is a method to compute a density function of a large number of arbitrary positive real functions.

Create a list of the functions required:

fs = Function[{s, t}, (1 + Cos[t - #]) (1 + Sin[s - #])] & /@ 
       RandomReal[{0, 2 π}, {1000}];

Compute the density plot by mapping the arguments over the functions and then summing them:

DensityPlot[Plus @@ (#[x, y] & /@ fs), {x, 0, 2 π}, {y, 0, 2 π}]

Mathematica graphics


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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