본문 바로가기
코딩 수업/파이썬 (업무자동화)

[업무 자동화] 학생들 Daily Quiz, Unit Test 점수로 그래프 만들기 (파이썬 코드, 학생 점수로 그래프 만드는 프로그램, To Create a Simple Graph with Students' Scores in Python)

by Jade S. 2025. 1. 19.
728x90
반응형
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib

# 한글 폰트 설정 (Windows에서는 'Malgun Gothic', macOS에서는 'AppleGothic' 등을 사용할 수 있음)
matplotlib.rcParams['font.family'] = 'Malgun Gothic'  # Windows에서 사용할 수 있는 한글 폰트
matplotlib.rcParams['axes.unicode_minus'] = False  # 마이너스 기호가 깨지지 않도록 설정

# 데이터 입력
data = {
    "Name": ["학생이름"] * 8,
    "Unit": [1, 1, 1, 1, 2, 2, 2, 2],
    "Lesson": [1, 2, 3, 4, 1, 2, 3, 4],
    "Score": [97, 97, 94, 95, 97, 94, 97, 100]
}

# 데이터프레임 생성
df = pd.DataFrame(data)

# Lesson을 연속된 번호로 변경
df['Global_Lesson'] = (df['Unit'] - 1) * 4 + df['Lesson']

# 선 그래프 그리기
plt.figure(figsize=(8, 5))
plt.plot(df['Global_Lesson'], df['Score'], marker='o', label="Score Trend")

# Lesson 4 강조: 빨간색 마커와 더 큰 마커
lesson4 = df[df['Lesson'] == 4]  # Lesson 4의 데이터
plt.scatter(lesson4['Global_Lesson'], lesson4['Score'], color='red', s=100, label='Unit Test (Lesson 4)', zorder=5)

# 그래프 제목에 아이의 이름 포함
plt.title(f"Score Trend for {df['Name'][0]} Across Units", fontsize=16)

# 그래프 꾸미기
plt.xlabel("Lesson", fontsize=12)
plt.ylabel("Score", fontsize=12)
plt.xticks(df['Global_Lesson'], labels=[f"U{u}L{l}" for u, l in zip(df['Unit'], df['Lesson'])])
plt.legend()
plt.grid()

# Y축 범위 설정
plt.ylim(0, 100)  # 0부터 100까지 설정

# 그래프 출력
plt.show()

 

✔️결과물

728x90
반응형