【发布时间】:2011-08-10 18:44:08
【问题描述】:
我试图使用 Python 脚本和 matplotlib 绘制 MySQL 结果
import MySQLdb
import matplotlib.pyplot as plt
conn = MySQLdb.connect (host = "localhost",
user = "testuser",
passwd = "testpass",
db = "test")
cursor = conn.cursor ()
cursor.execute ("SELECT id,secondid from table limit 10")
row = cursor.fetchall()
print "RESULT:", row[0]
cursor.close ()
conn.close ()
我将通过像这样的简单传递来绘制这两个列表
id,ts=zip(*row) #cThis will solve the problem
plt.plot(id,secondid)
plt.grid()
但是我很困惑创建两个列表,因为查询结果是一个元组列表。 请建议。
【问题讨论】:
-
留下这个问题。我得到了答案 id,secondid=zip(*row)
-
如果你已经解决了,请将解决方案作为答案发布,而不是评论,并接受它。
-
对不起。我不知道这东西是新手。我已经提交了答案。谢谢
标签: python matplotlib