본문 바로가기

카테고리 없음

macOS에서 matplotlib 한글 표시 안될때

macOS에서 matplotlib를 사용하여 한글을 표시할 때, 기본적으로 한글을 지원하지 않는 폰트가 사용되어 아래와 같은 경고가 발생할 수 있습니다. 이 문제를 해결하기 위해 한글을 지원하는 폰트로 변경해야 합니다.

 

<stdin>:1: UserWarning: Glyph 51064 (\N{HANGUL SYLLABLE IN}) missing from current font.
<stdin>:1: UserWarning: Glyph 45937 (\N{HANGUL SYLLABLE DEG}) missing from current font.
<stdin>:1: UserWarning: Glyph 49828 (\N{HANGUL SYLLABLE SEU}) missing from current font.
<stdin>:1: UserWarning: Glyph 44144 (\N{HANGUL SYLLABLE GEO}) missing from current font.
<stdin>:1: UserWarning: Glyph 44984 (\N{HANGUL SYLLABLE GGU}) missing from current font.
<stdin>:1: UserWarning: Glyph 47196 (\N{HANGUL SYLLABLE RO}) missing from current font.

matplotlib의 rcParams를 사용하여 전역 글꼴 속성을 변경할 수 있습니다. macOS에 설치된 한글 폰트 중 하나를 선택하여 설정할 수 있으며, AppleGothic이 많이 사용되는 폰트 중 하나입니다.

다음은 matplotlib에서 한글 폰트를 설정하는 방법입니다:

 

import matplotlib.pyplot as plt
import matplotlib as mpl

# matplotlib의 글꼴을 설정합니다.
mpl.rcParams['font.family'] = 'AppleGothic'
mpl.rcParams['axes.unicode_minus'] = False  # 마이너스 기호 문제 해결