I want to plot a real time, time series data using plotly. But I need a datetime generator to be created first that will act as an input to the plot. I also want to limit the graph to show data for latest 30 mins records only.
the below code is in javascript, I want to perform something similar in python:
function rand() {
return Math.random();
}
var time = new Date();
var data = [{
x: [time],
y: [rand],
mode: 'lines',
line: {color: '#80CAF6'}
}]
Plotly.newPlot('myDiv', data);
var cnt = 0;
var interval = setInterval(function() {
var time = new Date();
var update = {
x: [[time]],
y: [[rand()]]
}
var olderTime = time.setMinutes(time.getMinutes() - 1);
var futureTime = time.setMinutes(time.getMinutes() + 1);
var minuteView = {
xaxis: {
type: 'date',
range: [olderTime,futureTime]
}
};
Plotly.relayout('myDiv', minuteView);
Plotly.extendTraces('myDiv', update, [0])
if(++cnt === 100) clearInterval(interval);
}, 1000);