我试图以这种方式绘制来自两个不同来源的在线数据:
在每次迭代中:
1]第一个来源:将输入数据添加到图表中。
2]第二个来源:删除以前的数据并仅保留图中的传入数据。
这是我的代码:
import plotly.plotly as py
import plotly.tools as tls
from plotly.graph_objs import *
import numpy as np
from sklearn.cluster import MeanShift, estimate_bandwidth
from sklearn.datasets.samples_generator import make_blobs
import time
py.sign_in('wajdi', 'key')
trace1 = Scatter(
x=[],
y=[],
mode='markers',
marker=Marker(
color=[],
opacity=1,
line=Line(width=0.0),
size=[],symbol='circle'),
stream=Stream(token='troi4k35qp'),
)
trace2 = Scatter(
x=[],
y=[],
mode='markers',
marker=Marker(color=[]),
stream=Stream(token='8lsvl6a79e')
)
data = Data([trace1,trace2])
layout = Layout(title='Time Series')
fig = Figure(data=data, layout=layout)
unique_url = py.plot(fig, filename='s7_first-stream')
s = py.Stream('8lsvl6a79e')
z = py.Stream('troi4k35qp')
s.open()
z.open()
print "waiting for brower..."
time.sleep(6)
centers = [[15, 15],[5, 5]]
for i in range(1000):
X, _ = make_blobs(n_samples=2, centers=centers, cluster_std=1.0,center_box=(-1, 1))
print i
s.write(dict(x=X[0,0], y=X[0,1],marker=Marker(color='blue')))
z.write(dict(x=X[1,0], y=X[1,1],marker=Marker(color='green',size=15)))
time.sleep(0.9)
# I WANT TO REMOVE DATA WRITED IN Z STREAM HERE
s.close()
z.close()
print "finish"
答案 0 :(得分:1)