이번에는 데이터 시각화 중 가장 많이 사용하는 pie chart에 대하여 정리하였다.
원을 부채꼴로 분할하여 표현하는 통계차트로
전체를 백분위로 나타낼 때 유용하다.


기본적인 코드는 아래와 같다.
fig, ax = plt.subplots(1, 1, figsize=(7, 7))
ax.pie(data,labels=['A','B','C'])
plt.show()
fig, ax = plt.subplots(1, 1, figsize=(7, 7))
ax.pie(data,labels=['A','B','C','D'],startanle=90)
plt.show()
fig, ax = plt.subplots(1, 1, figsize=(7, 7))
explode = [0, 0, 0.2, 0] # 얼마나 튀어나갈 것인가
ax.pie(data, labels=labels, explode=explode, startangle=90,textprops={'color':'w'})
plt.show()
fig, ax = plt.subplots(1, 1, figsize=(7, 7))
explode = [0, 0, 0.2, 0] # 얼마나 튀어나갈 것인가
ax.pie(data, labels=labels, explode=explode, startangle=90,textprops={'color':'w'},
shadow=True)
plt.show()
fig, ax = plt.subplots(1, 1, figsize=(7, 7))
explode = [0, 0, 0.2, 0]
ax.pie(data, labels=labels, explode=explode, startangle=90,
shadow=True, autopct='%1.1f%%',textprops={'color':'w'})
plt.show()
fig, ax = plt.subplots(1, 1, figsize=(7, 7))
explode = [0, 0, 0.2, 0]
ax.pie(data, labels=labels, explode=explode, startangle=90,
shadow=True, autopct='%1.1f%%',textprops={'color':'w'},
labeldistance=1.5, rotatelabels=90)
plt.show()
counterclock=Trueradius = 1 또는 0.8 등등 숫자fig, ax = plt.subplots(1, 1, figsize=(7, 7))
ax.pie(data, labels=labels, startangle=90,
shadow=True, autopct='%1.1f%%')
# 좌표 0, 0, r=0.7, facecolor='white'
centre_circle = plt.Circle((0,0),0.70,fc='white')
ax.add_artist(centre_circle)
plt.show()
-> 중간에 흰원이 추가된 chart가 나온다.
fig, ax = plt.subplots(1, 1, figsize=(7, 7))
ax.pie(data, labels=labels, startangle=90,
shadow=True, autopct='%1.1f%%')
# 좌표 0, 0, r=0.7, facecolor='white'
centre_circle = plt.Circle((0,0),0.70,fc='white')
ax.add_artist(centre_circle)
plt.show()
위의 그래프에서 pctdistance를 0.85로 지정하였는데
이는 0.7과 1 사이이기 때문에 그래프 가운데에 그려진다.
