Black Lives Matter. Please consider donating to Black Girls Code today.

Extend multiple traces

Is it possible to extend multiple traces using extendTraces function?

xi = xi + 1;
var update = {
x: [[ xi ]],
y:[[ Math.random() ]]
}

Plotly.extendTraces(plotDiv, update, [0], 10);

Can I create an “update” to extend two traces (“trace1”, “trace2”) on the same scatter plot ?

Thanks,
Sergey

Any luck mate so far…?? I am also having a problem with a huge amount of data points (180k) that needs to be drawn… solution to your problem can also help me…

Here’s how: http://codepen.io/etpinard/pen/qZzyXp

xi = xi + 1;
var update = {
  x:  [[ xi /* that extends trace0 */ ], [ xi /* that extends trace1 */ ]],
  y: [[ Math.random() ], [ Math.random() ] ]
}
1 Like

Awesome! thanks.:+1:

Hi @etienne

I have two questions:

  1. When zoomed in, updates can no longer be seen, but a snapshot at last value?

  2. Any idea if connecting via MONGO_URL i.e
    var MONGO_URL = ‘mongodb://ec2-XX-XX-XXX-XX.us-west-2.compute.amazonaws.com:27017/mystoredata’;

I need to deserialize first or work directly with Plotly? i.e my data format is every 30 mins

{
  "_id" : ObjectId("57d9209236b7c31958782bd2"),
  "point_id" : "130-E9DCE6-1327/10",
  "time" : "01/08/2015 01:30",
  "offset" : 1,
  "energy" : 29,
  "code" : 0,
  "created_date" : ISODate("2016-09-14T00:00:00Z")
}
{
  "_id" : ObjectId("57d9209236b7c31958782bd3"),
  "point_id" : "130-E9DCE6-1327/10",
  "time" : "01/08/2015 02:00",
  "offset" : 1,
  "energy" : 28,
  "code" : 0,
  "created_date" : ISODate("2016-09-14T00:00:00Z")
}

and I like to plot energy vs time

Solved it for me as well to extend traces in dash dcc.Graph:

@app.callback(
Output(‘temperature-graphs’,‘extendData’),
[Input(‘graph-update’, ‘n_intervals’)],
[State(‘temperature-graphs’, ‘figure’)])
def extend_graph(n_intervals, existing):
# some code to get the new data
ls = {‘x’: [[time[0][0]], [time[0][0]]], ‘y’: [[watertemp[0][0]], [environmenttemp[0][0]]]}, [0, 1]
return ls

Thanks!