Allen's 데이터 맛집

Matplotlib 한글 깨짐 오류 : UserWarning: Glyph 45936 (\N{HANGUL SYLLABLE DE}) missing from current font. 본문

Programming/Python

Matplotlib 한글 깨짐 오류 : UserWarning: Glyph 45936 (\N{HANGUL SYLLABLE DE}) missing from current font.

Allen93 2024. 7. 5. 11:18

Python으로 쥬피터 노트북으로 Matplotlib 그래프를 그릴 때 아래와 같은 문구와 함께 그래프 상에서 한글이 깨짐 현상을 가질 때가 있습니다.

 


 

C:\ProgramData\anaconda3\Lib\site-packages\IPython\core\pylabtools.py:152: UserWarning: Glyph 45936 (\N{HANGUL SYLLABLE DE}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) C:\ProgramData\anaconda3\Lib\site-packages\IPython\core\pylabtools.py:152: UserWarning: Glyph 51060 (\N{HANGUL SYLLABLE I}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) C:\ProgramData\anaconda3\Lib\site-packages\IPython\core\pylabtools.py:152: UserWarning: Glyph 53552 (\N{HANGUL SYLLABLE TEO}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) C:\ProgramData\anaconda3\Lib\site-packages\IPython\core\pylabtools.py:152: UserWarning: Glyph 53440 (\N{HANGUL SYLLABLE TA}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) C:\ProgramData\anaconda3\Lib\site-p

 


...

 

그럴땐 해당 코드를 삽입하여 해결이 가능합니다.

import matplotlib.pyplot as plt
import matplotlib.font_manager as fm

# 한글 폰트 설정
font_path = 'C:/Windows/Fonts/malgun.ttf'  # Windows용 경로 예시
font_name = fm.FontProperties(fname=font_path).get_name()
plt.rc('font', family=font_name)
plt.rcParams['axes.unicode_minus'] = False  # 마이너스 부호 설정

# 샘플 그래프
plt.plot([1, 2, 3], [4, 5, 6])
plt.title('한글 제목')
plt.xlabel('X 축')
plt.ylabel('Y 축')
plt.show()

위의 코드를 쥬피터 노트북에 복사하여 실행하면 한글이 정상적으로 표시되는지 확인할 수 있습니다. 만약 다른 폰트를 사용하고 싶다면 font_path 변수에 해당 폰트의 경로를 지정해줍니다.

이렇게 설정하면 matplotlib에서 한글 폰트가 정상적으로 표시됩니다.

728x90