@@ -42,7 +42,7 @@ def adjust_placement(row):
42
42
43
43
def create_bar_plot (x , y ,title ,xlabel ):
44
44
buf = io .BytesIO ()
45
- plt .figure (figsize = (8 ,6 ))
45
+ plt .figure (figsize = (10 ,6 ))
46
46
bars = plt .barh (x ,y , color = 'skyblue' , edgecolor = 'black' )
47
47
max_index = np .argmax (y .values )
48
48
min_index = np .argmin (y .values )
@@ -51,9 +51,10 @@ def create_bar_plot(x, y,title,xlabel):
51
51
for bar in bars :
52
52
width = bar .get_width ()
53
53
plt .text (width + 0.5 , bar .get_y () + bar .get_height () / 2 ,
54
- f'{ width :.2f} ' , va = 'center' , fontsize = 10 , color = 'black' )
54
+ f'{ width :.2f} ' , va = 'center' , fontsize = 15 , color = 'black' )
55
55
plt .title (title , fontsize = 16 , fontweight = 'bold' )
56
- plt .xlabel (xlabel , fontsize = 12 )
56
+ plt .xlabel (xlabel , fontsize = 21 ,fontweight = 'bold' , color = '#34495e' , labelpad = 10 , family = 'serif' )
57
+
57
58
plt .xlim (0 , 100 )
58
59
plt .tight_layout ()
59
60
plt .gca ().invert_yaxis ()
@@ -69,16 +70,16 @@ def top_students():
69
70
name = x ['Name_x' ]
70
71
marks = x ['Marks' ]
71
72
branch = x ['Branch' ]
72
- plt .figure (figsize = (12 ,5 ))
73
+ plt .figure (figsize = (12 ,7 ))
73
74
plot = sns .barplot (data = df , x = name , y = marks , hue = branch )
74
75
for p in plot .patches :
75
76
height = p .get_height ()
76
77
plot .annotate (f'{ height :.1f} ' ,
77
78
(p .get_x () + p .get_width () / 2. , height ),
78
79
ha = 'center' , va = 'bottom' ,
79
- fontsize = 9 , color = 'black ' )
80
- plt .legend (title = 'Branch' , loc = 'center left' , bbox_to_anchor = (1 , 0.5 ), fontsize = 'small' , title_fontsize = 'small ' )
81
- plt .xticks (rotation = 45 )
80
+ color = 'black' , fontsize = 12 , fontweight = 'bold ' )
81
+ plt .legend (title = 'Branch' , loc = 'center left' , bbox_to_anchor = (1 , 0.5 ), title_fontsize = 'medium ' )
82
+ plt .xticks (rotation = 70 , fontsize = 16 , fontweight = 'bold' , family = 'serif' )
82
83
plt .title ("Student Marks by Branch" )
83
84
plt .tight_layout ()
84
85
plt .savefig (buf , format = 'png' )
@@ -103,8 +104,8 @@ def scatter():
103
104
plt .figure (figsize = (8 , 6 ))
104
105
sns .scatterplot (data = new_df , x = df ['Attendance' ], y = new_df ['Marks' ], hue = new_df ['Branch' ], s = 100 )
105
106
plt .title ("Attendance vs Marks" )
106
- plt .xlabel ("Attendance" )
107
- plt .ylabel ("Marks" )
107
+ plt .xlabel ("Attendance" , fontsize = 17 , fontweight = 'bold' )
108
+ plt .ylabel ("Marks" , fontsize = 17 , fontweight = 'bold' )
108
109
plt .grid (True )
109
110
plt .tight_layout ()
110
111
plt .savefig (buf , format = 'png' )
@@ -118,28 +119,34 @@ def fees_status():
118
119
119
120
buf = io .BytesIO ()
120
121
grouped = df .groupby (['Branch' , 'Fees_status' ]).size ().reset_index (name = 'count' )
121
- plt .figure (figsize = (10 , 6 ))
122
- sns .barplot (data = grouped , x = 'Branch' , y = 'count' , hue = 'Fees_status' , palette = 'Set2' )
122
+ plt .figure (figsize = (10 ,7 ))
123
+ sns .barplot (data = grouped , x = 'Branch' , y = 'count' , hue = 'Fees_status' , palette = 'Set2' , )
123
124
plt .title ('Fee Status by Branch' )
124
- plt .xlabel ('Branch' )
125
- plt .ylabel ('Number of Students' )
126
- plt .legend (title = 'Fees Status' )
127
- plt .xticks (rotation = 45 )
125
+ plt .xlabel ('Branch' ,fontsize = 17 ,fontweight = 'bold' )
126
+ plt .ylabel ('Number of Students' ,fontsize = 17 ,fontweight = 'bold' )
127
+ plt .legend (title = 'Fees Status' ,loc = 'upper right' )
128
+ plt .xticks (rotation = 80 , fontsize = 12 ,fontweight = 'bold' , color = '#34495e' , family = 'serif' )
129
+ for p in plt .gca ().patches :
130
+ plt .gca ().annotate (f'{ int (p .get_height ())} ' ,
131
+ (p .get_x () + p .get_width () / 2. , p .get_height ()),
132
+ ha = 'center' , va = 'bottom' , fontsize = 12 , fontweight = 'bold' )
133
+
128
134
plt .tight_layout ()
135
+ plt .grid (True )
129
136
plt .savefig (buf , format = 'png' )
130
137
plt .close ()
131
138
buf .seek (0 )
132
139
return base64 .b64encode (buf .read ()).decode ('utf-8' )
133
140
def placement_status ():
134
141
buf = io .BytesIO ()
135
- plt .figure (figsize = (6 ,4 ))
142
+ plt .figure (figsize = (6 ,5 ))
136
143
sns .set (style = "whitegrid" )
137
144
palette = {'Placed' : "#1f77b4" , 'Unplaced' : "#ff7f0e" }
138
145
sns .countplot (data = df , x = 'Placed' ,palette = palette ,width = 0.3 )
139
146
plt .legend (title = 'Placement Status' , loc = 'upper right' , labels = ['Placed' , 'Unplaced' ], fontsize = 12 )
140
147
plt .title ("Number of Students Placed vs Unplaced" , fontsize = 16 , fontweight = 'bold' )
141
- plt .xlabel ("Placement Status" , fontsize = 12 )
142
- plt .ylabel ("Number of Students" , fontsize = 12 )
148
+ plt .xlabel ("Placement Status" ,fontsize = 17 , fontweight = 'bold' )
149
+ plt .ylabel ("Number of Students" ,fontsize = 17 , fontweight = 'bold' )
143
150
for p in plt .gca ().patches :
144
151
plt .gca ().annotate (f'{ int (p .get_height ())} ' ,
145
152
(p .get_x () + p .get_width () / 2. , p .get_height ()),
@@ -159,9 +166,9 @@ def branch_placement():
159
166
sns .countplot (data = df , x = 'Branch' , hue = 'Placed' , palette = palette )
160
167
161
168
plt .title ("Branch-wise Placement Status" , fontsize = 16 , fontweight = 'bold' )
162
- plt .xlabel ("Branch" , fontsize = 12 )
163
- plt .ylabel ("Number of Students" , fontsize = 12 )
164
- plt .xticks (rotation = 45 )
169
+ plt .xlabel ("Branch" , fontsize = 17 , fontweight = 'bold' )
170
+ plt .ylabel ("Number of Students" , fontsize = 17 , fontweight = 'bold' )
171
+ plt .xticks (rotation = 45 , fontsize = 12 , fontweight = 'bold' , color = '#34495e' , family = 'serif' )
165
172
for p in plt .gca ().patches :
166
173
height = p .get_height ()
167
174
if height > 0 :
@@ -181,8 +188,8 @@ def branch_placement():
181
188
182
189
183
190
print (json .dumps ({'result' :{
184
- 'barplot1' :create_bar_plot (branches ,att_mean ,"Engineering Branch Scores" ,"Attendance" ),
185
- 'barplot2' :create_bar_plot (branches ,marks_mean ,"Engineering Branch Scores" ,"Marks" ),
191
+ 'barplot1' :create_bar_plot (branches ,att_mean ,"Engineering Branch Scores" ,"Attendance (Mean) " ),
192
+ 'barplot2' :create_bar_plot (branches ,marks_mean ,"Engineering Branch Scores" ,"Marks (Mean) " ),
186
193
'scatter' :scatter (),
187
194
'top_students' :top_students (),
188
195
'pieplot' :pieplot (),
0 commit comments