#连接数据库开启游标获取数据
db = pymysql.connect(host='localhost',user='root',passwd='cbj123',port=3306,db='bigdata')
cur = db.cursor()
sql ='select * from student'
cur.execute(sql)
see = cur.fetchall()#定义空数据数组将数据库数据附上去
sname =[]
chinese =[]
math =[]
english =[]for data in see:
sname.append(data[0])
chinese.append(data[1])
math.append(data[2])
english.append(data[3])..................#关闭游标与数据库
cur.close()
db.close()
import numpy as np
import matplotlib.pyplot as plt
import pymysql
#连接数据库开启游标获取数据
db = pymysql.connect(host='localhost',user='root',passwd='cbj123',port=3306,db='bigdata')
cur = db.cursor()
sql ='select * from student'
cur.execute(sql)
see = cur.fetchall()#定义空数据数组将数据库数据附上去
sname =[]
chinese =[]
math =[]
english =[]for data in see:
sname.append(data[0])
chinese.append(data[1])
math.append(data[2])
english.append(data[3])
width =0.2
index = np.arange(len(sname))
r1 = plt.bar(sname,chinese,width,color='r',label='chinese')
r2 = plt.bar(index+width,math,width,color='b',label='math')
r3 = plt.bar(index+width+width,english,width,color='c',label='english')#显示图像
plt.legend()
plt.show()
cur.close()
db.close()