How to remove points from the start of the plotted trace data

I am receiving data being sent live from a piece of hardware that is running continuously. Right now I start with a blank scatter plot and I’m calling Plotly.extendTraces to append the new data to the plot. This works great. However as you may imagine, since the data just keeps coming in, my plot just gets more and more data. What I need is to be able to purge the oldest plotted values when new values are appended, so that I have a moving window in time displayed in the plot.

How do I delete data from the start of the trace to achieve this?

I created this codepen:

See https://plot.ly/javascript/plotlyjs-function-reference/#plotlyextendtraces

For example, calling

// extend multiple traces up to a maximum of 10 points per trace
Plotly.extendTraces(graphDiv, {y: [[rand()], [rand()]]}, [0, 1], 10)

keeps only the most recent 10 points.

1 Like

perfect, I totally missed that when looking at the docs.

1 Like