Window 환경입니다.
1. 폰트 다운 & 설치
저는 네이버 무료 폰트인 나눔체를 설치했습니다.
네이버 글꼴 모음
네이버가 만든 150여종의 글꼴을 한번에 만나보세요
hangeul.naver.com
설치를 진행 후 Window의 경우 .ttf 우클릭 \(\rightarrow\) 모든 사용자용으로 설치를 진행합니다.
(모든 사용자용으로 설치를 진행해야 C:\Windows\Fonts에 설치 됩니다. 그냥 설치하면 C:\Windows\User\AppData\... 에 설치 됩니다.)
2. matplotlibrc 수정
import matplotlib.font_manager as fm
import matplotlib as mpl
print(mpl.matplotlib_fname())
위 코드를 통해 matplotlibrc 위치를 알 수 있습니다.
1. matplotlibrc를 메모장으로 열어 ctrl+f 로 font.family를 찾습니다.
2. 주석을 해제하고 원하는 폰트명으로 수정합니다.
3. cache 제거
matplotlib cache가 있다면, 폰트가 제대로 적용되지 않습니다.
import matplotlib.font_manager as fm
import matplotlib as mpl
print(mpl.get_cachedir())
위 코드를 통해 cache 위치를 알 수 있습니다.
1. 설치되어 있는 fontlist-v390 (숫자가 다를 수 있음) 를 제거합니다. (혹시 모르니 바탕하면에 복사를 진행합시다.)
2. jupyter의 경우 restart, conda의 경우 deactivate, activate를 통해 재시작을 진행합니다.
4. 설치 확인
import matplotlib.font_manager as fm
font_list = fm.findSystemFonts(fontpaths=None, fontext='ttf')
print(font_list)
위 코드를 통해 font_list에 설치한 폰트가 있는지 확인합니다.
import matplotlib.pyplot as plt
plt.title('테스트')
plt.show()
한글이 제대로 출력되는지 확인합니다.
5. - (마이너스) 가 깨질 경우
matplotlibrc에서 axes.unicode_minus를 찾아 False로 변경합니다.
'Develop > Python' 카테고리의 다른 글
[Python] Window에 pyenv 설치 (0) | 2025.01.02 |
---|---|
[Error] / [Pyinstaller] xgboost XGBoostLibraryNotFound error (1) | 2024.11.29 |
[Python] 리스트의 원소 곱 - reduce (0) | 2024.01.11 |
[Python] 화면 캡쳐 라이브러리 처리 속도 비교 (0) | 2023.11.02 |
[Python] pytube로 Youtube 영상 처리 (0) | 2023.07.18 |