카테고리 없음
14. 원 그래프 (심화)
_션샤인
2024. 7. 2. 17:01
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family'] = 'Malgun Gothic'
matplotlib.rcParams['font.size'] = 15
matplotlib.rcParams['axes.unicode_minus'] = False
values = [30, 25, 20, 13, 10, 2] #원그래프 그릴 때 values 와 labels 필요함.
labels = ['Python', 'Java', 'Javascript', 'C#', 'C/C++', 'ETC']
plt.pie(values, labels=labels, autopct='%.1f%%', startangle = 90, counterclock = False)
plt.show()
values = [30, 25, 20, 13, 10, 2] #원그래프 그릴 때 values 와 labels 필요함.
labels = ['Python', 'Java', 'Javascript', 'C#', 'C/C++', 'ETC']
colors = ['#ffadad', '#ffd6a5', '#fdffb6', '#caffbf', '#9bf6ff', '#a0c4ff']
explode = [0.05]*6
plt.pie(values, labels=labels, autopct='%.1f%%', startangle = 90, counterclock = False, colors = colors, explode = explode)
plt.show()
wedgeprops={'width':0.6} #도넛의 두께 결정
plt.pie(values, labels=labels, autopct='%.1f%%', startangle = 90, counterclock = False, colors = colors, wedgeprops=wedgeprops)
plt.show()
def custom_autopct(pct):
#return('%.1f%%' % pct) if pct >=10 else ''
#return'{:.1f}%'.format(pct) if pct >=10 else ''
plt.pie(values, labels=labels, autopct=custom_autopct, startangle = 90, counterclock = False, colors = colors, wedgeprops=wedgeprops)
plt.show()
def custom_autopct(pct):
#return('%.1f%%' % pct) if pct >=10 else ''
return'{:.0f}%'.format(pct) if pct >=10 else ''
plt.pie(values, labels=labels, autopct=custom_autopct, startangle = 90, counterclock = False, colors = colors, wedgeprops=wedgeprops, pctdistance=0.7)
plt.show()
DataFrame 활용
import pandas as pd
df = pd.read_excel('../pandas/score.xlsx')
df
grp = df.groupby('학교')
grp
grp.size()['북산고']
values = [grp.size()['북산고'], grp.size()['능남고']]
labels = ['북산고', '능남고']
plt.pie(values, labels = labels)
plt.title('소속 학교')
plt.show()