한글폰트가 깨집니다
1469
작성한 질문수 3
def get_font_family():
"""
시스템 환경에 따른 기본 폰트명을 반환하는 함수
"""
import platform
system_name = platform.system()
# colab 사용자는 system_name이 'Linux'로 확인
if system_name == "Darwin" :
font_family = "AppleGothic"
elif system_name == "Windows":
font_family = "Malgun Gothic"
else:
!apt-get install fonts-nanum -qq > /dev/null
!fc-cache -fv
import matplotlib as mpl
mpl.font_manager._rebuild()
findfont = mpl.font_manager.fontManager.findfont
mpl.font_manager.findfont = findfont
mpl.backends.backend_agg.findfont = findfont
font_family = "NanumBarunGothic"
return font_family
이렇게 설정하고 get_font_family()하면 'Malgun Gothic' 제대로 나오고
# 시각화를 위한 폰트설정
import matplotlib.pyplot as plt
# 위에서 만든 함수를 통해 시스템 폰트를 불러와서 font_family 라는 변수에 할당
font_family = get_font_family()
# 폰트설정
plt.rc("font", family = "font_family")
# 마이너스폰트 설정
plt.rc("axes", unicode_minus = False)
그래프 스타일 설정
plt.style.use("ggplot")
이걸 돌렸는데도
# 한글폰트 확인
pd.Series([1, -3]).plot(title="한글폰트")
하면 깨져서 나옵니다.
C:\Users\August\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:240: RuntimeWarning: Glyph 54620 missing from current font. font.set_text(s, 0.0, flags=flags)
어떻게 하면 좋을까요?
답변 2
1
안녕하세요.
아마 윈도우 기본폰트에 맑은 고딕이 없는 것으로 보여집니다.
아래 명령어를 conda prompt 를 열어 설치해 주세요!
pip install koreanize-matplotlib
그리고 주피터 노트북을 열어 아래의 코드를 실행해 보세요.
koreanize_matplotlib 은 설치하고 불러오는 것만으로도 한글폰트 사용이 가능합니다.
import koreanize_matplotlib
# 그래프에 retina display 적용
%config InlineBackend.figure_format = 'retina'
pd.Series([1, 3, 5, -7, 9]).plot(title="한글")
0
For 아이패드 사용자
저는 출퇴근길에 아이패드에서 보다보니 환경이 조금 달랐습니다.
비슷한 경우가 있었는데 아래처럼 아이패드 기본 폰트로 설정하니 됐어요.
def get_font_family():
"""
시스템 환경에 따른 기본 폰트명을 반환하는 함수
"""
import platform
system_name = platform.system()
# colab 사용자는 system_name이 'Linux'로 확인
if system_name == "Darwin" :
# font_family = "AppleGothic"
font_family = "Apple SD Gothic Neo"
elif system_name == "Windows":
font_family = "Malgun Gothic"
else:
# Linux
# colab에서는 runtime을 <꼭> 재시작 해야합니다.
# 런타임을 재시작 하지 않고 폰트 설치를 하면 기본 설정 폰트가 로드되어 한글이 깨집니다.
!apt-get update -qq
!apt-get install fonts-nanum -qq > /dev/null
import matplotlib.font_manager as fm
fontpath = '/usr/share/fonts/truetype/nanum/NanumBarunGothic.ttf'
font = fm.FontProperties(fname=fontpath, size=9)
fm._rebuild()
font_family = "NanumBarunGothic"
return font_family
cufflinks 버전문제로 iplot() 미실행
0
47
2
[수정요청]직접 수집한 주가 데이터로 시각화해보기
0
55
2
pd.read_html(url, encoding='cp949') 에러
0
78
2
fdr.StockListing('KRX') 문제 발생
0
145
2
주식 자동매매 프로그램 제작 관련 조언 부탁드립니다
0
435
1
concat 을 통한 데이터 프레임 합치기 에러 문의
0
108
2
한글폰트 관련해서 문의드립니다.
0
235
2
데이터프레임 칼럼명 문의 드립니다.
0
239
3
금융데이터 수집의 모든것
0
146
2
녹화시점과 현재시점 컬럼명이 변경이 많이 되었을까요?
0
193
2
파이썬 증권 데이터 수집과 분석으로 신호와 소음 찾기 - 섹션1 [2/2]
0
176
1
Mac 환경에서 nbextensions 활성화 하는 방법
0
601
2
pd.concat(result.tolist()) 오류 문의
0
249
1
5.1 제약 데이터 수집 오류 해결
0
232
1
Table of contents 문의드립니다
0
216
2
concat을 통한 데이터프레임 합치기
0
552
2
Reindexing only valid with uniquely valued Index objects 오류 질문입니다.
0
495
1
데이터 비교시 데이터 불일치
0
414
1
dtype={"itemcode": np.object}) 을 dtype={"itemcode": object}) 으로 변경해야 하나요?
0
599
1
질문 : for문 풀어쓰기
0
493
1
파이참에서 Plotly 그래프 실행방법
0
1310
1
5.1 데이터프레임 병합(merge)
0
744
2
쥬피터노트북에서 실행파일 만들기
0
1452
1
주피터노트북 확장팩 설치가 안됩니다.
0
566
2





