如何在Python中密谋解决此语法错误?这段代码正确吗?

时间:2019-04-02 04:38:53

标签: python plotly-python

我正在尝试从数据库中读取数据,然后创建一个图形并将其使用plotly库保存为png图像文件。我已经使用过matplotlib来绘制数据图,并且工作正常。但是,第19行的代码中存在语法错误,导致该代码无法运行。

我试图通过缩进线条或将其进一步向下或向上移动来解决错误,但没有成功。

databaseName = '/home/A_Database/sensehat.db'

plotly.tools.set_credentials_file(username='******', api_key='******')

def check():
    conn=sqlite3.connect(databaseName)
    curs=conn.cursor()
    curs.execute("SELECT * FROM A1")
    results = curs.fetchall()
    temperature=[]
    timestamp=[]

    for row in results:
        trace = go.Scatter(x = timestamp ['Time Stamp'], y = temperature ['Temperature'], 
        name = 'Temperature/Time Stamp',
         layout = go.Layout(title = 'Temperature Graph', showlegend = True)

fig=go.Figure(data=[trace], layout = layout)

py.iplot(fig, filename='Test.png')
check()

我希望它只是将完整的图形发送到我在plotly网站上的帐户,但是由于语法错误而无法使用。

1 个答案:

答案 0 :(得分:0)

您似乎正在尝试绘制空白列表。您不应该在绘图循环中使用变量row吗?包含来自数据库的结果。