코딩
코랩에서 seaborn 및 matplotlib에서 한글 깨짐 현상
도아죻아
2023. 7. 5. 18:50
반응형
2시간을 헤매면서 chatGPT 수십번들 두드리다가 드디어 찾았다.
#폰트 설치
!sudo apt-get install -y fonts-nanum
!sudo fc-cache -fv
!rm ~/.cache/matplotlib -rf
위와같이 폰트를 설치하고 런타임 재시작을 한다
plt.rc('font', family='NanumBarunGothic')
맷플롯플립에서 폰트를 적용하고 실행한다.
끝~
아래는 참고용
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
plt.rc('font', family='NanumBarunGothic')
# 데이터 불러오기 및 처리
df = pd.read_csv('/content/sample_data/230630퀀트필터링(샘플).csv', error_bad_lines=False, encoding='euc-kr')
df_filled = df.fillna(0)
# 히트맵 그리기
plt.figure(figsize=(30, 15))
sns.heatmap(df_filled.corr(), annot=True)
# 그래프 출력
plt.show()
반응형