树莓皮上的Python/使用Plotly绘制5种温度。数据中重复的x个值。每分钟更新一次。不流。fileopt=";扩展;

树莓皮上的Python/使用Plotly绘制5种温度。数据中重复的x个值。每分钟更新一次。不流。fileopt=";扩展;,python,extend,plotly,Python,Extend,Plotly,我正在使用运行Python 3的Raspberry Pi记录来自5个温度传感器的数据 一切都很顺利,我现在想在一张图表上显示5种温度的曲线图,大约每10分钟更新一次。我想用Plotly 我编写了以下代码来测试这个想法 #many_lines2 # tryimg to sort out why x is sent more than once when using extend import time import plotly.plotly as py fr

我正在使用运行Python 3的Raspberry Pi记录来自5个温度传感器的数据

一切都很顺利,我现在想在一张图表上显示5种温度的曲线图,大约每10分钟更新一次。我想用Plotly

我编写了以下代码来测试这个想法

#many_lines2

    # tryimg to sort out why x is sent more than once when using extend

    import time

    import plotly.plotly as py
    from plotly.graph_objs import *
    import plotly.tools as tls
    #tls.set_credentials_file(username=, api_key)
    from datetime import datetime


    for count in range  (1,5):

        x1 = count
        y1 = count * 2
        y2 = count * 3
        y3 = count * 4



        trace1 = Scatter(x=x1,y = y1,mode = "lines")
        trace2 = Scatter(x=x1,y = y2,mode = "lines")
        trace3 = Scatter(x=x1,y = y3,mode = "lines")

        data = [trace1,trace2,trace3]

        py.plot (data,filename="3lines6", fileopt = "extend")

        time.sleep(60)
请参见此处的plotly接收的绘图和数据 有关plotly接收的数据,请参见数据选项卡

在我看来,数据表中的x值似乎在发送第一个值后添加了三次

通过在python中使用.append创建值列表,我可以获得正确的结果。这导致了长长的列表,更多的数据被发送到plotly,而且似乎是错误的

下面是执行此操作的代码,可以在此处找到plotly Service上的数据

我在网上搜索过,可以找到数据流的例子,但我只想每10分钟或更长时间更新一次绘图

我是否错过了一些明显的东西

干杯


史蒂夫

安德鲁从这里来。非常感谢您将此记录得如此之好

编辑 现在应该修复此问题,这使得以下解决方法过时/不正确。请不要再使用以下解决方法!(但将其保存在此处以备记录)

TL;博士(让它工作起来) 请尝试以下代码:

import time
import plotly.plotly as py
from plotly.graph_objs import Figure, Scatter
filename = 'Stack Overflow 31436471'

# setup original figure (behind the scenes, Plotly assumes you're sharing that x source)
# note that the x arrays are all the same and the y arrays are all *different*
fig = Figure()
fig['data'].append(Scatter(x=[0], y=[1], mode='lines'))
fig['data'].append(Scatter(x=[0], y=[2], mode='lines'))
fig['data'].append(Scatter(x=[0], y=[3], mode='lines'))

print py.plot(fig, filename=filename, auto_open=False)
# --> https://plot.ly/~theengineear/4949

# start extending the plots
for i in xrange(1, 3):
    x1 = i
    y1 = i * 2
    y2 = i * 3
    y3 = i * 4

    fig = Figure()
    # note that since the x arrays are shared, you only need to extend one of them
    fig['data'].append(Scatter(x=x1, y=y1))
    fig['data'].append(Scatter(y=y2))
    fig['data'].append(Scatter(y=y3))

    py.plot(fig, filename=filename, fileopt='extend', auto_open=False)

    time.sleep(2)
更多信息 这似乎是我们后端代码中的一个bug。问题是我们重用散列为相同值的数据数组。在这种情况下,您的
x
值正在散列到相同的值,当您要扩展跟踪时,实际上是将相同的
x
数组扩展了三次

上面提出的修复方法只扩展了x阵列中的一个,这与其他跟踪所使用的阵列相同

请注意,要使其工作,您必须在初始设置中提供非零长度数组。这是因为如果Plotly没有任何数据开始,它将不会保存数组

需要注意的是,只要您初始化相同的
x
数组,并确保在初始化过程中您的
y
数组与任何
x
数组都不相同,您就可以了


为不便的解决方法道歉。我将在我们端提交修复程序后编辑此响应。

查看位于的“数据”选项卡。我想你需要停止加x三次了。谢谢你,安德鲁。稍后我将发布到绘图的链接。史蒂夫
import time
import plotly.plotly as py
from plotly.graph_objs import Figure, Scatter
filename = 'Stack Overflow 31436471'

# setup original figure (behind the scenes, Plotly assumes you're sharing that x source)
# note that the x arrays are all the same and the y arrays are all *different*
fig = Figure()
fig['data'].append(Scatter(x=[0], y=[1], mode='lines'))
fig['data'].append(Scatter(x=[0], y=[2], mode='lines'))
fig['data'].append(Scatter(x=[0], y=[3], mode='lines'))

print py.plot(fig, filename=filename, auto_open=False)
# --> https://plot.ly/~theengineear/4949

# start extending the plots
for i in xrange(1, 3):
    x1 = i
    y1 = i * 2
    y2 = i * 3
    y3 = i * 4

    fig = Figure()
    # note that since the x arrays are shared, you only need to extend one of them
    fig['data'].append(Scatter(x=x1, y=y1))
    fig['data'].append(Scatter(y=y2))
    fig['data'].append(Scatter(y=y3))

    py.plot(fig, filename=filename, fileopt='extend', auto_open=False)

    time.sleep(2)