使用plotly

时间:2018-11-22 08:07:45

标签: python stream plotly

我正在努力通过以不同的颜色显示异常点来显示流中的异常。我正在用图来流数据。当前它以红色显示所有点。有人可以看看我的代码,对其进行纠正或提出建议。

def setColor(y):
   if y in list(theOutliersDF_TP.index): return 'red'
   else: return 'yellow'

username = plotly_user_config['plotly_username']
api_key = plotly_user_config['plotly_api_key']
stream_token = plotly_user_config['plotly_streaming_tokens'][0]
p = plotly.plotly.sign_in(username, api_key)

plotly.plotly.iplot([{'x': [], 'y': [], 'type': 'scatter', 'mode': 'lines+markers', 'line': dict(color='green'),
                  'marker': dict(color=list(map(setColor,anomalies))),
                  'stream': {'token': stream_token}
                  }], filename='Tiime-Series', fileopt='extend')

s = plotly.plotly.Stream(stream_token)
s.open()
i = 0

while True:
  x_data_point = theOutliersDF_TP['index'].iloc[i]
  y_data_point = theOutliersDF_TP['weight'].iloc[i]
  i += 1
  s.write({'x': x_data_point, 'y': y_data_point})
  time.sleep(80. / 1000.)

0 个答案:

没有答案