データ分析と可視化
20731 ワード
11.累積棒グラフ
12.複数の棒グラフ
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family'] = 'Malgun Gothic' #windows
matplotlib.rcParams['font.size'] = 15
matplotlib.rcParams['axes.unicode_minus'] = False
df = pd.read_excel('../Pandas/score3.xlsx')
df

plt.bar(df['이름'], df['국어'], label='국어')
plt.bar(df['이름'], df['영어'], bottom=df['국어'], label='영어')
plt.ylim(0, 250)
plt.legend()

#plt.bar(df['이름'], df['국어'], label='국어')
plt.bar(df['이름'], df['영어'], bottom=df['국어'], label='영어')
plt.ylim(0, 250)
plt.legend()

plt.bar(df['이름'], df['국어'], label='국어')
plt.bar(df['이름'], df['영어'], bottom = df['국어'], label='영어')
plt.bar(df['이름'], df['수학'], bottom = df['국어'] + df['영어'], label='수학')
#plt.ylim(0, 250)
plt.xticks(rotation=60)
plt.legend()

12.複数の棒グラフ
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family'] = 'Malgun Gothic' #windows
matplotlib.rcParams['font.size'] = 15
matplotlib.rcParams['axes.unicode_minus'] = False
df = pd.read_excel('../Pandas/score3.xlsx')
df

import numpy as np
np.arange(5)
>>> array([0, 1, 2, 3, 4])
np.arange(3,6)
>>> array([3, 4, 5])
arr = np.arange(5)
arr
>>> array([0, 1, 2, 3, 4])
arr+100
>>> array([100, 101, 102, 103, 104])
arr*3
>>> array([ 0, 3, 6, 9, 12])
df.shape[0]
>>> 8
N = df.shape[0]
N
>>> 8
index = np.arange(N)
index
>>> array([0, 1, 2, 3, 4, 5, 6, 7])
w =0.25
plt.bar(index - w, df['국어'])
#x의 위치가 약간 옆으로 가있음
plt.bar(index, df['영어'])
plt.bar(index + w, df['수학'])

w =0.25
plt.bar(index - w, df['국어'], width=w, label= '국어')
plt.bar(index, df['영어'], width=w, label= '영어')
plt.bar(index + w, df['수학'], width=w, label= '수학' )
plt.legend(ncol=3)

plt.figure(figsize=(10, 5))
plt.title('학생별 성적')
w =0.25
plt.bar(index - w, df['국어'], width=w, label= '국어')
plt.bar(index, df['영어'], width=w, label= '영어')
plt.bar(index + w, df['수학'], width=w, label= '수학' )
plt.legend(ncol=3)
plt.xticks(index, df['이름'], rotation=60)
plt.show()

Reference
この問題について(データ分析と可視化), 我々は、より多くの情報をここで見つけました https://velog.io/@ssjy89/나도코딩-데이터-분석-및-시각화-Matplotlib5テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol