数据存储在一个名为“data”的数据库中,其中包含“month”和“traffic”两列。该表如下所示:
+-----------+---------+
| month | traffic |
+-----------+---------+
| January | 1000 |
| February | 100 |
| March | 10430 |
| April | 1500 |
| May | 100 |
| June | 1200 |
| July | 800 |
| August | 8000 |
| September | 100000 |
+-----------+---------+
现在我已经使用 python 从数据库中提取了数据。我希望使用这些数据进行绘图。这是我的代码:
#usr/bin/python
import MySQLdb as mdb
import rpy2.robjects as robjects
r = robjects.r
def database():
"""Retrieves the data from the database"""
#Database Connection
con = mdb.connect('localhost', 'root', 'devil', 'data');
with con:
#Submit statements to SQL server
cursor = con.cursor()
cursor.execute("SELECT * FROM traffic")
#Retrieves data from SQL
rows = cursor.fetchall()
for row in rows:
row = list(row)
x = row[1:]
y = row[:-1]
r.plot(x, y)
database()
我想使用变量 x 进行绘图,而 yrplot(x, y) 不起作用。这是错误:
res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error in plot.window(...) : need finite 'ylim' values
我该如何绘图?