본문 바로가기
FullStack/22. Python

[Python] matplotlib 그래프 한글 깨짐

by nakanara 2020. 11. 28.
반응형

Python

matplotlib 그래프 한글 깨짐

matplotlib을 이용하여 그린 그래프에서 한글이 깨져서 표시가 된다.
해당 현상을 피하려면 Font를 변경해줘야 한다.

현상

import matplotlib
import sys
import pandas as pd


df = pd.read_csv('data/score.csv')
df.index = df['이름']
df['국어'].plot(kind='bar')

image

수정

import matplotlib
import platform

print(platform.system()) # 플랫폼 확인

# Window
if platform.system() == 'Windows':
    matplotlib.rc('font', family='Malgun Gothic')
elif platform.system() == 'Darwin': # Mac
    matplotlib.rc('font', family='AppleGothic')
else: #linux
    matplotlib.rc('font', family='NanumGothic')

# 그래프에 마이너스 표시가 되도록 변경
matplotlib.rcParams['axes.unicode_minus'] = False

df.index = df['이름']
df['국어'].plot(kind='bar')

image

#python #matplotlib #그래프 #한글깨짐

반응형

'FullStack > 22. Python' 카테고리의 다른 글

데이터 딕셔너리 자료형  (0) 2020.12.07
데이터 튜플 자료형  (0) 2020.12.07
[IPython] %matplotlib inline 의미  (0) 2020.11.27
[Python] 리스트 자료형  (0) 2020.11.18
연산 및 제어문  (0) 2020.11.17