본문 바로가기

Python

[Python] matplotlib 한글 깨짐 (Windos, Mac)

df = pd.DataFrame(dataset,
                  index=pd.date_range('03/1-2022', periods=100),
                  columns=['한글이', '나오나요?', '나올까요?'])
df.plot()

위와 같이 matplotlib에서 한글을 사용하면 

 

한글이 깨져서 나온다. 

 

해결 방법

 

Windows

font_name = matplotlib.font_manager.FontProperties(fname=
                                    'c:/windows/fonts/malgun.ttf').get_name()
matplotlib.rc('font', family=font_name)
matplotlib.rcParams['axes.unicode_minus']=False

 

Mac

from matplotlib import rc
rc('font', family='AppleGothic')
plt.rcParams['axes.unicode_minus'] = False

 

해결완료