반응형
파이썬 한글 폰트 시 깨지는 설정이 없으면 깨집니다.
한글폰트 미설정 시 깨짐현상
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, -4, 6, -5, 3]
plt.plot(x, y)
plt.title('한글 시 깨짐')
코드 한 줄 추가하여 설정을 수정해보겠습니다.
한글폰트 코드추가
import matplotlib
matplotlib.rcParams['font.family'] = 'Malgun Gothic' # Window 사용 시
# matplotlib.rcParams['font.family'] = 'AppleGothic' # Mac 사용 시
추가옵션(사이즈 및 마이너스 표기)
import matplotlib
matplotlib.rcParams['font.family'] = 'Malgun Gothic'
matplotlib.rcParams['font.size'] = 8 # 글자크기
matplotlib.rcParams['axes.unicode_minus'] = False # 한글 폰트 사용 시 마이너스 표기
글자 폰트를 원하는 폰트로 수정하고 싶을 경우에는 폰트 변경이 가능합니다.
import matplotlib.font_manager as fm
fm.fontManager.ttflist # 사용가능한 폰트 확인
저 같은 경우에는 'Gmarket Sans'용으로 한번 변경해보았습니다.
import matplotlib.font_manager as fm
[f.name for f in fm.fontManager.ttflist if 'gmarket' in f.name.lower()]
이런 식으로 코드를 입력하면 'gmarket'이 포함된 폰트를 불러와줍니다.
결과 )
['Gmarket Sans TTF', 'Gmarket Sans TTF', 'Gmarket Sans TTF']
한글폰트 최종설정
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family'] = 'Gmarket Sans TTF'
matplotlib.rcParams['font.size'] = 8 # 글자크기
matplotlib.rcParams['axes.unicode_minus'] = False # 한글 폰트 사용 시 마이너스 표기
x = [1, 2, 3]
y = [2, -4, 6]
plt.plot(x, y);
plt.title('한글폰트 입력완료')
반응형
'파이썬(Python)' 카테고리의 다른 글
엑셀 데이터를 R에 붙여넣기 / R데이터를 엑셀에 붙여넣기 (0) | 2024.08.05 |
---|---|
Python 데이터를 엑셀에 붙여넣기 / 엑셀 데이터를 파이썬에 붙여넣기 (0) | 2024.08.05 |
파이썬으로 가상의 데이터 만들기(Feat. Faker) (0) | 2023.07.16 |
[Pandas활용] pd.cut / pd.qcut을 이용하여 빈도수 확인하기 (0) | 2023.05.01 |
[Python] Jupyterlab 자동 괄호닫기, 따옴표 닫기 설정 (0) | 2023.01.27 |
댓글