python - plotly:从图中删除绘制的数据
python - plotly: remove plotted data from graph
我正在尝试以这种方式绘制来自两个不同来源的在线数据:
在每次迭代中:
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"
您可以通过发送空数组来删除(或者如果愿意,也可以清除)流中的数据。在您的情况下,只需添加
z.write(x=[], y=[])
有关完整示例,请参阅此 ipython notebook:
我正在尝试以这种方式绘制来自两个不同来源的在线数据:
在每次迭代中:
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"
您可以通过发送空数组来删除(或者如果愿意,也可以清除)流中的数据。在您的情况下,只需添加
z.write(x=[], y=[])
有关完整示例,请参阅此 ipython notebook: