ProfessorLeVesseur commited on
Commit
89ef316
·
verified ·
1 Parent(s): 1329e4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -429,27 +429,29 @@ def compute_student_metrics(df):
429
  # # Display the plot
430
  # st.pyplot(fig)
431
 
 
 
432
  def plot_student_metrics(student_metrics_df):
433
  # Create the figure and axis
434
  fig, ax = plt.subplots(figsize=(10, 6)) # Increased figure size for better readability
435
-
436
- # Width for the bars and offset for overlapping effect
437
- bar_width = 0.4
438
  index = range(len(student_metrics_df))
439
 
440
- # Plot Attendance and Engagement bars side by side with transparency
441
- attendance_bars = ax.bar([i - bar_width/2 for i in index], student_metrics_df['Attendance (%)'],
442
  width=bar_width, label='Attendance (%)', color='#005288', alpha=0.7)
443
- engagement_bars = ax.bar([i + bar_width/2 for i in index], student_metrics_df['Engagement (%)'],
444
- width=bar_width, label='Engagement (%)', color='#3AB0FF', alpha=0.7)
445
 
446
- # Add labels to each bar with customized font size and color
447
- font_size = 8 # Reduced font size for better fit
448
  for bar in attendance_bars:
449
  height = bar.get_height()
450
  ax.text(bar.get_x() + bar.get_width() / 2, height, f'{height:.1f}%',
451
  ha='center', va='bottom', color='white', fontsize=font_size)
452
-
453
  for bar in engagement_bars:
454
  height = bar.get_height()
455
  ax.text(bar.get_x() + bar.get_width() / 2, height, f'{height:.1f}%',
@@ -463,6 +465,9 @@ def plot_student_metrics(student_metrics_df):
463
  ax.set_xticks(index)
464
  ax.set_xticklabels(student_metrics_df['Student'], rotation=45, ha='right') # Improved xticklabel alignment
465
 
 
 
 
466
  # Tight layout to ensure all elements fit within the figure
467
  fig.tight_layout()
468
 
@@ -470,7 +475,6 @@ def plot_student_metrics(student_metrics_df):
470
  st.pyplot(fig)
471
 
472
  return fig
473
- return fig
474
 
475
  # def plot_student_metrics(student_metrics_df):
476
  # # Create the figure and axis
 
429
  # # Display the plot
430
  # st.pyplot(fig)
431
 
432
+ import matplotlib.pyplot as plt
433
+
434
  def plot_student_metrics(student_metrics_df):
435
  # Create the figure and axis
436
  fig, ax = plt.subplots(figsize=(10, 6)) # Increased figure size for better readability
437
+
438
+ # Width for the bars
439
+ bar_width = 0.35
440
  index = range(len(student_metrics_df))
441
 
442
+ # Plot Attendance and Engagement bars with transparency
443
+ attendance_bars = ax.bar(index, student_metrics_df['Attendance (%)'],
444
  width=bar_width, label='Attendance (%)', color='#005288', alpha=0.7)
445
+ engagement_bars = ax.bar(index, student_metrics_df['Engagement (%)'],
446
+ width=bar_width * 0.7, label='Engagement (%)', color='#3AB0FF', alpha=0.7) # Skinnier engagement bars
447
 
448
+ # Add labels to each bar
449
+ font_size = 10 # Font size for the labels
450
  for bar in attendance_bars:
451
  height = bar.get_height()
452
  ax.text(bar.get_x() + bar.get_width() / 2, height, f'{height:.1f}%',
453
  ha='center', va='bottom', color='white', fontsize=font_size)
454
+
455
  for bar in engagement_bars:
456
  height = bar.get_height()
457
  ax.text(bar.get_x() + bar.get_width() / 2, height, f'{height:.1f}%',
 
465
  ax.set_xticks(index)
466
  ax.set_xticklabels(student_metrics_df['Student'], rotation=45, ha='right') # Improved xticklabel alignment
467
 
468
+ # Set y-axis limits from 0 to 100%
469
+ ax.set_ylim(0, 100)
470
+
471
  # Tight layout to ensure all elements fit within the figure
472
  fig.tight_layout()
473
 
 
475
  st.pyplot(fig)
476
 
477
  return fig
 
478
 
479
  # def plot_student_metrics(student_metrics_df):
480
  # # Create the figure and axis