-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
32 lines (25 loc) · 827 Bytes
/
plot.py
File metadata and controls
32 lines (25 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import matplotlib.pyplot as plt
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="",
database="attendance")
mycursor = mydb.cursor()
# Count total students
mycursor.execute("SELECT COUNT(*) FROM o_python")
totalS = mycursor.fetchone()[0]
# Count total present students
mycursor.execute("SELECT COUNT(*) FROM o_python WHERE status = 'Present'")
presentS = mycursor.fetchone()[0]
# Count total absent students
absentS = totalS - presentS
# Data to plot
labels = 'Present Students', 'Absent Students'
sizes = [presentS, absentS]
colors = ['yellow', 'blue']
explode = (0.03, 0) # explode 1st slice
# Plot
plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%0.2f%%')
#plt.axis('equal')
plt.show()