inflearn logo
강의

Khóa học

Chia sẻ kiến thức

Tìm kiếm tín hiệu và nhiễu bằng cách thu thập và phân tích dữ liệu chứng khoán bằng Python

데이터 시각화 도구 소개와 한글폰트 설정 에러

2282

amethis

4 câu hỏi đã được viết

1

데이터 시각화 도구 소개와 한글폰트 설정 에러

위에 강좌를 실습 중에 에러가 발생합니다.

우분투, 주피터노트북 사용, 나눔바른고딕 폰트 있습니다.

도와주세요!!!!

 

1. 우분투에 나눔바른고딕 폰트 있음: 제가 실습하는 환경

(base) root@gd-virtual-machine:/usr/share/fonts/truetype/nanum# lsb_release -d

Description:    Ubuntu 20.04.4 LTS

(base) root@gd-virtual-machine:/usr/share/fonts/truetype/nanum#

(base) root@gd-virtual-machine:/usr/share/fonts/truetype/nanum#

(base) root@gd-virtual-machine:/usr/share/fonts/truetype/nanum# ls NanumBarunGothic.ttf

NanumBarunGothic.ttf

(base) root@gd-virtual-machine:/usr/share/fonts/truetype/nanum#

 

2. 에러 발생(강의 코드)

def get_font_family():

    import platform

    system_name = platform.system()

    

    if system_name == "Darwin" :

        font_family = "AppleGothic"

    elif system_name == "Windows":

        font_family = "Malgun Gothic"

    else:

        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

 

AttributeError                            Traceback (most recent call last)

/tmp/ipykernel_1662/385091406.py in <module>

----> 1 get_font_family()

 

/tmp/ipykernel_1662/3056356644.py in get_font_family()

     11         fontpath = '/usr/share/fonts/truetype/nanum/NanumBarunGothic.ttf'

     12         font = fm.FontProperties(fname=fontpath, size=9)

---> 13         fm._rebuild()

     14         font_family = "NanumBarunGothic"

     15     return font_family

 

AttributeError: module 'matplotlib.font_manager' has no attribute '_rebuild'

 

3. 에러 발생(수업자료 소스 코드)

def get_font_family():

    """

    시스템 환경에 따른 기본 폰트명을 반환하는 함수

    """

    import platform

    system_name = platform.system()

 

    if system_name == "Darwin" :

        font_family = "AppleGothic"

    elif system_name == "Windows":

        font_family = "Malgun Gothic"

    else:

        # Linux(colab)

        !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

 

/usr/share/fonts: caching, new cache contents: 0 fonts, 6 dirs

/usr/share/fonts/X11: caching, new cache contents: 0 fonts, 4 dirs

/usr/share/fonts/X11/Type1: caching, new cache contents: 8 fonts, 0 dirs

/usr/share/fonts/X11/encodings: caching, new cache contents: 0 fonts, 1 dirs

/usr/share/fonts/X11/encodings/large: caching, new cache contents: 0 fonts, 0 dirs

/usr/share/fonts/X11/misc: caching, new cache contents: 89 fonts, 0 dirs

/usr/share/fonts/X11/util: caching, new cache contents: 0 fonts, 0 dirs

/usr/share/fonts/cMap: caching, new cache contents: 0 fonts, 0 dirs

/usr/share/fonts/cmap: caching, new cache contents: 0 fonts, 5 dirs

/usr/share/fonts/cmap/adobe-cns1: caching, new cache contents: 0 fonts, 0 dirs

/usr/share/fonts/cmap/adobe-gb1: caching, new cache contents: 0 fonts, 0 dirs

/usr/share/fonts/cmap/adobe-japan1: caching, new cache contents: 0 fonts, 0 dirs

/usr/share/fonts/cmap/adobe-japan2: caching, new cache contents: 0 fonts, 0 dirs

/usr/share/fonts/cmap/adobe-korea1: caching, new cache contents: 0 fonts, 0 dirs

/usr/share/fonts/opentype: caching, new cache contents: 0 fonts, 3 dirs

/usr/share/fonts/opentype/malayalam: caching, new cache contents: 7 fonts, 0 dirs

/usr/share/fonts/opentype/noto: caching, new cache contents: 28 fonts, 0 dirs

/usr/share/fonts/opentype/urw-base35: caching, new cache contents: 35 fonts, 0 dirs

/usr/share/fonts/truetype: caching, new cache contents: 0 fonts, 50 dirs

/usr/share/fonts/truetype/Gargi: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/Gubbi: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/Nakula: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/Navilu: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/Sahadeva: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/Sarai: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/abyssinica: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/arphic: caching, new cache contents: 0 fonts, 0 dirs

/usr/share/fonts/truetype/dejavu: caching, new cache contents: 6 fonts, 0 dirs

/usr/share/fonts/truetype/droid: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/fonts-beng-extra: caching, new cache contents: 6 fonts, 0 dirs

/usr/share/fonts/truetype/fonts-deva-extra: caching, new cache contents: 3 fonts, 0 dirs

/usr/share/fonts/truetype/fonts-gujr-extra: caching, new cache contents: 5 fonts, 0 dirs

/usr/share/fonts/truetype/fonts-guru-extra: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/fonts-kalapi: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/fonts-orya-extra: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/fonts-telu-extra: caching, new cache contents: 2 fonts, 0 dirs

/usr/share/fonts/truetype/fonts-yrsa-rasa: caching, new cache contents: 10 fonts, 0 dirs

/usr/share/fonts/truetype/freefont: caching, new cache contents: 12 fonts, 0 dirs

/usr/share/fonts/truetype/kacst: caching, new cache contents: 15 fonts, 0 dirs

/usr/share/fonts/truetype/kacst-one: caching, new cache contents: 2 fonts, 0 dirs

/usr/share/fonts/truetype/lao: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/liberation: caching, new cache contents: 16 fonts, 0 dirs

/usr/share/fonts/truetype/liberation2: caching, new cache contents: 12 fonts, 0 dirs

/usr/share/fonts/truetype/lohit-assamese: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/lohit-bengali: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/lohit-devanagari: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/lohit-gujarati: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/lohit-kannada: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/lohit-malayalam: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/lohit-oriya: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/lohit-punjabi: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/lohit-tamil: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/lohit-tamil-classical: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/lohit-telugu: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/lyx: caching, new cache contents: 11 fonts, 0 dirs

/usr/share/fonts/truetype/malayalam: caching, new cache contents: 10 fonts, 0 dirs

/usr/share/fonts/truetype/nanum: caching, new cache contents: 31 fonts, 0 dirs

/usr/share/fonts/truetype/noto: caching, new cache contents: 2 fonts, 0 dirs

/usr/share/fonts/truetype/openoffice: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/padauk: caching, new cache contents: 4 fonts, 0 dirs

/usr/share/fonts/truetype/pagul: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/samyak: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/samyak-fonts: caching, new cache contents: 3 fonts, 0 dirs

/usr/share/fonts/truetype/sinhala: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/tibetan-machine: caching, new cache contents: 1 fonts, 0 dirs

/usr/share/fonts/truetype/tlwg: caching, new cache contents: 58 fonts, 0 dirs

/usr/share/fonts/truetype/ttf-bitstream-vera: caching, new cache contents: 10 fonts, 0 dirs

/usr/share/fonts/truetype/ttf-khmeros-core: caching, new cache contents: 2 fonts, 0 dirs

/usr/share/fonts/truetype/ubuntu: caching, new cache contents: 14 fonts, 0 dirs

/usr/share/fonts/type1: caching, new cache contents: 0 fonts, 1 dirs

/usr/share/fonts/type1/urw-base35: caching, new cache contents: 35 fonts, 0 dirs

/root/anaconda3/fonts: skipping, no such directory

/root/.local/share/fonts: skipping, no such directory

/root/.fonts: skipping, no such directory

/usr/share/fonts/X11: skipping, looped directory detected

/usr/share/fonts/cMap: skipping, looped directory detected

/usr/share/fonts/cmap: skipping, looped directory detected

/usr/share/fonts/opentype: skipping, looped directory detected

/usr/share/fonts/truetype: skipping, looped directory detected

/usr/share/fonts/type1: skipping, looped directory detected

/usr/share/fonts/X11/Type1: skipping, looped directory detected

/usr/share/fonts/X11/encodings: skipping, looped directory detected

/usr/share/fonts/X11/misc: skipping, looped directory detected

/usr/share/fonts/X11/util: skipping, looped directory detected

/usr/share/fonts/cmap/adobe-cns1: skipping, looped directory detected

/usr/share/fonts/cmap/adobe-gb1: skipping, looped directory detected

/usr/share/fonts/cmap/adobe-japan1: skipping, looped directory detected

/usr/share/fonts/cmap/adobe-japan2: skipping, looped directory detected

/usr/share/fonts/cmap/adobe-korea1: skipping, looped directory detected

/usr/share/fonts/opentype/malayalam: skipping, looped directory detected

/usr/share/fonts/opentype/noto: skipping, looped directory detected

/usr/share/fonts/opentype/urw-base35: skipping, looped directory detected

/usr/share/fonts/truetype/Gargi: skipping, looped directory detected

/usr/share/fonts/truetype/Gubbi: skipping, looped directory detected

/usr/share/fonts/truetype/Nakula: skipping, looped directory detected

/usr/share/fonts/truetype/Navilu: skipping, looped directory detected

/usr/share/fonts/truetype/Sahadeva: skipping, looped directory detected

/usr/share/fonts/truetype/Sarai: skipping, looped directory detected

/usr/share/fonts/truetype/abyssinica: skipping, looped directory detected

/usr/share/fonts/truetype/arphic: skipping, looped directory detected

/usr/share/fonts/truetype/dejavu: skipping, looped directory detected

/usr/share/fonts/truetype/droid: skipping, looped directory detected

/usr/share/fonts/truetype/fonts-beng-extra: skipping, looped directory detected

/usr/share/fonts/truetype/fonts-deva-extra: skipping, looped directory detected

/usr/share/fonts/truetype/fonts-gujr-extra: skipping, looped directory detected

/usr/share/fonts/truetype/fonts-guru-extra: skipping, looped directory detected

/usr/share/fonts/truetype/fonts-kalapi: skipping, looped directory detected

/usr/share/fonts/truetype/fonts-orya-extra: skipping, looped directory detected

/usr/share/fonts/truetype/fonts-telu-extra: skipping, looped directory detected

/usr/share/fonts/truetype/fonts-yrsa-rasa: skipping, looped directory detected

/usr/share/fonts/truetype/freefont: skipping, looped directory detected

/usr/share/fonts/truetype/kacst: skipping, looped directory detected

/usr/share/fonts/truetype/kacst-one: skipping, looped directory detected

/usr/share/fonts/truetype/lao: skipping, looped directory detected

/usr/share/fonts/truetype/liberation: skipping, looped directory detected

/usr/share/fonts/truetype/liberation2: skipping, looped directory detected

/usr/share/fonts/truetype/lohit-assamese: skipping, looped directory detected

/usr/share/fonts/truetype/lohit-bengali: skipping, looped directory detected

/usr/share/fonts/truetype/lohit-devanagari: skipping, looped directory detected

/usr/share/fonts/truetype/lohit-gujarati: skipping, looped directory detected

/usr/share/fonts/truetype/lohit-kannada: skipping, looped directory detected

/usr/share/fonts/truetype/lohit-malayalam: skipping, looped directory detected

/usr/share/fonts/truetype/lohit-oriya: skipping, looped directory detected

/usr/share/fonts/truetype/lohit-punjabi: skipping, looped directory detected

/usr/share/fonts/truetype/lohit-tamil: skipping, looped directory detected

/usr/share/fonts/truetype/lohit-tamil-classical: skipping, looped directory detected

/usr/share/fonts/truetype/lohit-telugu: skipping, looped directory detected

/usr/share/fonts/truetype/lyx: skipping, looped directory detected

/usr/share/fonts/truetype/malayalam: skipping, looped directory detected

/usr/share/fonts/truetype/nanum: skipping, looped directory detected

/usr/share/fonts/truetype/noto: skipping, looped directory detected

/usr/share/fonts/truetype/openoffice: skipping, looped directory detected

/usr/share/fonts/truetype/padauk: skipping, looped directory detected

/usr/share/fonts/truetype/pagul: skipping, looped directory detected

/usr/share/fonts/truetype/samyak: skipping, looped directory detected

/usr/share/fonts/truetype/samyak-fonts: skipping, looped directory detected

/usr/share/fonts/truetype/sinhala: skipping, looped directory detected

/usr/share/fonts/truetype/tibetan-machine: skipping, looped directory detected

/usr/share/fonts/truetype/tlwg: skipping, looped directory detected

/usr/share/fonts/truetype/ttf-bitstream-vera: skipping, looped directory detected

/usr/share/fonts/truetype/ttf-khmeros-core: skipping, looped directory detected

/usr/share/fonts/truetype/ubuntu: skipping, looped directory detected

/usr/share/fonts/type1/urw-base35: skipping, looped directory detected

/usr/share/fonts/X11/encodings/large: skipping, looped directory detected

/root/anaconda3/var/cache/fontconfig: cleaning cache directory

/root/.cache/fontconfig: not cleaning non-existent cache directory

/root/.fontconfig: not cleaning non-existent cache directory

fc-cache: succeeded

---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

/tmp/ipykernel_1662/385091406.py in <module>

----> 1 get_font_family()

 

/tmp/ipykernel_1662/3296694249.py in get_font_family()

     16 

     17         import matplotlib as mpl

---> 18         mpl.font_manager._rebuild()

     19         findfont = mpl.font_manager.fontManager.findfont

     20         mpl.font_manager.findfont = findfont

 

AttributeError: module 'matplotlib.font_manager' has no attribute '_rebuild'

    

데이터시각화 한글폰트 pandas 우분투 python 파이썬 웹-크롤링 numpy seaborn matplotlib 웹 스크래핑 plotly

Câu trả lời 1

1

todaycode

안녕하세요!

강의 제작 당시에는 폰트를 설치해서 사용하는 것으로 제작했는데  아래의 라이브러리가 공개되어 아래 라이브러리를 사용해 보는것을 추천합니다.

설치와 import 만으로도 한글폰트를 사용하실 수 있습니다.

github : https://github.com/ychoi-kr/koreanize-matplotlib

설치

pip install koreanize-matplotlib

또는

python setup.py install

import matplotlib.pyplot as plt
import koreanize_matplotlib

plt.plot([-1, 0, 1, 2])
plt.xlabel('간단한 그래프')
plt.show()

0

amethis

해결되었습니다. 너무 너무 감사합니다...!!!!

cufflinks 버전문제로 iplot() 미실행

0

44

2

[수정요청]직접 수집한 주가 데이터로 시각화해보기

0

52

2

pd.read_html(url, encoding='cp949') 에러

0

75

2

fdr.StockListing('KRX') 문제 발생

0

137

2

주식 자동매매 프로그램 제작 관련 조언 부탁드립니다

0

431

1

concat 을 통한 데이터 프레임 합치기 에러 문의

0

105

2

한글폰트 관련해서 문의드립니다.

0

230

2

데이터프레임 칼럼명 문의 드립니다.

0

239

3

금융데이터 수집의 모든것

0

145

2

녹화시점과 현재시점 컬럼명이 변경이 많이 되었을까요?

0

192

2

파이썬 증권 데이터 수집과 분석으로 신호와 소음 찾기 - 섹션1 [2/2]

0

175

1

Mac 환경에서 nbextensions 활성화 하는 방법

0

594

2

pd.concat(result.tolist()) 오류 문의

0

244

1

5.1 제약 데이터 수집 오류 해결

0

231

1

Table of contents 문의드립니다

0

210

2

concat을 통한 데이터프레임 합치기

0

548

2

Reindexing only valid with uniquely valued Index objects 오류 질문입니다.

0

491

1

데이터 비교시 데이터 불일치

0

410

1

dtype={"itemcode": np.object}) 을 dtype={"itemcode": object}) 으로 변경해야 하나요?

0

593

1

질문 : for문 풀어쓰기

0

488

1

파이참에서 Plotly 그래프 실행방법

0

1308

1

5.1 데이터프레임 병합(merge)

0

742

2

쥬피터노트북에서 실행파일 만들기

0

1450

1

주피터노트북 확장팩 설치가 안됩니다.

0

562

2