Monte Carlo Plot


Can anyone point me to an example of how to make a plot with 1000 (or more) lines in plotly? Looking to plot 1000 Monte Carlo simulations. I’ve tried to use cufflinks to plot a DataFrame but I get an error that it will take too long.



I`m not sure if I understood you the right way. I made a plot to visualise marathon runners pace a while ago. Please, take a look.
Marathon analysis.

There are 2 similar charts near the end of notebook. It could take a while to render that notebook.


Hi @dpsugasa, won’t do so well if you represent each of 1000+ lines as individual traces. You’ll have much better luck if you group all of your lines (or at least all of your lines per color) into a single trace. This can be done by including nan values to separate your individual lines. I would also recommend using the scattergl trace types instead of scatter since scattergl is GPU optimized to handle much larger dataset sizes.

Here’s an example of plotting 1000 lines with 100 points each. Here representing 1000 trials of a 1D random walk for 100 iterations.

import numpy as np
import plotly.graph_objs as go
from plotly.offline import iplot, init_notebook_mode

N = 1000

# create list of the line segments you want to plot
all_xs = [np.arange(100, dtype='float64') for _ in range(N)]
all_ys = [(np.random.rand(100) - 0.5).cumsum() for _ in range(N)]

# append nan to each segment
all_xs_with_nan = [np.concatenate((xs, [np.nan])) for xs in all_xs]
all_ys_with_nan = [np.concatenate((ys, [np.nan])) for ys in all_ys]

# concatinate segments into single line
xs = np.concatenate(all_xs_with_nan)
ys = np.concatenate(all_ys_with_nan)

fig = go.Figure(data=[
    go.Scattergl(x=xs, y=ys, mode='lines', opacity=0.05, line={'color': 'darkblue'})

Hope that helps!


fantastic, thank you.


thank you, very helpful. And interesting notebook!