본문 바로가기

DATA SCIENCE

[Kaggle] kernel 내 plot에서 한글 깨짐 해결

 

import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.font_manager as fm
plt.rcParams['axes.unicode_minus'] = False
font_path = '/kaggle/input/nanum34/NanumSquareR.ttf'
font_name = fm.FontProperties(fname=font_path, size=10)#.get_name()
plt.rc('font', family=font_name.get_name())

## plt 입력 시 fontproperties=font_name 매개변수 넣어주기
gnr_code_name_plot = sns.barplot(x = 'gnr_code_name', y = 'song_cnt', data = gnr_count, order = gnr_list_desc)
gnr_code_name_plot.set_title('장르 별 매핑된 곡 수 분포', fontproperties=font_name)
gnr_code_name_plot.set_xlabel('대분류 장르코드', fontproperties=font_name)
gnr_code_name_plot.set_ylabel('곡 수', fontproperties=font_name)
plt.xticks(rotation = 90, fontproperties=font_name)
plt.show()
반응형