我按照情节示例使用我的 DHT22 传感器成功创建了流式温度图。传感器还提供了我想绘制的湿度。
有可能吗?以下代码是我正在尝试的,但引发了异常:没有数据被绘制到图表中(见下文)。plotly.exceptions.PlotlyAccountError: Uh oh, an error occured on the server.
with open('./plotly.conf') as config_file:
plotly_user_config = json.load(config_file)
py.sign_in(plotly_user_config["plotly_username"], plotly_user_config["plotly_api_key"])
streamObj = Stream(token=plotly_user_config['plotly_streaming_tokens'][0], maxpoints=4032)
trace1 = Scatter(x=[],y=[],stream=streamObj,name='Temperature')
trace2 = Scatter(x=[],y=[],yaxis='y2',stream=streamObj,name='Humidity')
data = Data([trace1,trace2])
layout = Layout(
title='Temperature and Humidity from DHT22 on RaspberryPI',
yaxis=YAxis(
title='Celcius'),
yaxis2=YAxis(
title='%',
titlefont=Font(color='rgb(148, 103, 189)'),
tickfont=Font(color='rgb(148, 103, 189)'),
overlaying='y',
side='right'))
fig = Figure(data=data, layout=layout)
url = py.plot(fig, filename='raspberry-temp-humi-stream')
dataStream = py.Stream(plotly_user_config['plotly_streaming_tokens'][0])
dataStream.open()
#MY SENSOR READING LOOP HERE
dataStream.write({'x': datetime.datetime.now(), 'y':s.temperature()})
dataStream.write({'x': datetime.datetime.now(), 'y':s.humidity()})
#END OF MY LOOP
更新1:
我修复了代码,不再抛出错误。但是仍然没有数据被绘制到图表上。我得到的只是轴: