Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Plotly.extendTraces() can extend error_x and error_y?

Hi,

I am using Plotly in a real-time streaming scenario and I need to display a scatter plot with statistical error bars. This is my trace object:
var trace = {
type: ‘scatter’,
mode: ‘markers’,
hoverinfo: ‘text’,
text: [],
x: [],
y: [],
marker: {
size:8,
symbol: [‘circle’]
},
error_x: {
array: [],
arrayminus: [],
symmetric: false,
type: ‘data’,
visible: true,
width: 0,
thickness : 1
},
error_y: {
array: [],
arrayminus: [],
symmetric: false,
type: ‘data’,
visible: true,
width: 0,
thickness : 1
},
};

Currently I am using the react() function in order to redraw the points each time new data arrive, but the performance decreases linearly as the number of points increases (with 300 points I have 0,4 s delay).

The extendTraces() function is what I should use to increment the performance, but apparently I can extend only the “x”, “y” and “text” (“trace-root-level”) arrays but not the “array” and “arrayminus” arrays that are located inside the error_x object.

This function call works,
Plotly.extendTraces(p, {text: [[ newText ]], y: [[ newY ]], x: [[ newX ]]}, [0])

I try to call the extendTraces() function with this other signature but it doesnt work:
Plotly.extendTraces(p, {text: [[ newText ]], y: [[ newY ]], x: [[ newX ]], error_x: { array: [[ newXError ]] } }, [0])

plotly.min.js:7 Uncaught Error: attribute error_x must be an array of length equal to indices array length

Thank you in advance.

extendTraces does not understand nested object, you need to use attribute strings. So something like:

Plotly.extendTraces(p, {text: [[ newText ]], y: [[ newY ]], x: [[ newX ]], 'error_x.array': [[ newXError ]] }, [0])

should work.

Thank you for the response. It works like a charm.
I have another question: I am highlighting certain “upper limit” points with an arrow facing down, using annotations.
Currently, I am pushing new annotations in the layout.annotations array and I use react() to display them.
This approach redraw all the annotations from scratch. Is there a way to draw only the last new annotation and dont delete (and redraw) the old ones? This also could improve the performarce…

Thank you for the response,
Cheers.