Why do I have to use a nested array when updating a plot?

This example states that a plot is updated using

var newArray = []
newArray.splice(0, 1)
var data_update = {
   y: [newArray]

Plotly.update('graph', data_update)

But why do I have to wrap the array of numbers into another array to make it work?

I read the docs and examples for plotly.restyle and plotly.update but could not find an explanation.

In the beginning when initializing the array it is just an array of numbers. Why are the square brackets needed to make it work when updating?

Any ideas?

(You can earn some points on SOF as the question is also there.)

I found the solution in the doc to Plotly.restyle:

In restyle, arrays are assumed to be used in conjunction with the trace indices provided. Therefore, to apply an array as a value, you need to wrap it in an additional array. For example:

// update two traces with new z data
var update = {z: [[[1,2,3], [2,1,2], [1,1,1]], [[0,1,1], [0,2,1], [3,2,1]]]};
Plotly.restyle(graphDiv, update, [1, 2])
1 Like