파이썬 데이터 분석 _ 시각화 결과 파일로 저장하기 : .savefig()

2025. 3. 9. 23:01LG U+ why not SW 5/python

 

 

 

 

 

파이썬

 

 

 

 

 

1.  모듈 import 및 데이터 추출, 시각화

import pandas as pd
import matplotlib.pyplot as plt

plt.rcParams['font.family'] = 'AppleGothic'
myframe = pd.read_csv('./data/allStoreModified.csv', index_col=0, encoding='utf-8')



print(myframe['brand'].unique())

#한글화
brand_dict = {'cheogajip':'처가집', 'goobne':'굽네',
              'nene':'네네', 'pelicana':'페리카나'}

mygrouping = myframe.groupby(['brand'])['brand']
chartData = mygrouping.count()

newindex = [brand_dict[idx] for idx in chartData.index]

chartData.index = newindex



mycolor = ['r', 'g', 'b', 'm']
plt.figure()
chartData.plot(kind = 'pie',
               legend = False,
               autopct = '%1.2f%%',
               colors = mycolor)

filename = 'myChickenGragh01.png'
plt.savefig(filename, dpi=400, bbox_inches='tight')
print(filename + '이(가) 저장되었습니다!')
plt.show()