카테고리 없음

11. 누적 막대 그래프

_션샤인 2024. 6. 30. 16:59
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family'] = 'Malgun Gothic'
matplotlib.rcParams['font.size'] = 15
matplotlib.rcParams['axes.unicode_minus'] = False
df = pd.read_excel('../Pandas/score.xlsx')
df

plt.bar(df['이름'], df['국어'])
plt.bar(df['이름'], df['영어'])

plt.bar(df['이름'], df['국어'])
plt.bar(df['이름'], df['영어'], bottom=df['국어'])

#막대그래프를 그릴 때 X축은 이름을, Y축은 점수를 넣는데, 밑(bottom=국어) 데이터를 넣은 후 그 위에 영어 점수를 쌓겠다는 뜻

 

plt.bar(df['이름'], df['국어'])
plt.bar(df['이름'], df['영어'], bottom=df['국어'])
plt.bar(df['이름'], df['수학'], bottom=df['국어'] + df['영어'])

plt.bar(df['이름'], df['국어'], label = '국어')
plt.bar(df['이름'], df['영어'], bottom=df['국어'], label = '영어')
plt.bar(df['이름'], df['수학'], bottom=df['국어'] + df['영어'], label = '수학')

plt.xticks(rotation=60)
plt.legend()