Skip to main content
  1. Guides/

Fixing broken Korean text in Python Matplotlib

·96 words
Table of Contents

Issue
#

Matplotlib default font does not have Korean characters so Korean text outputs as blocks when plotting figures.

import matplotlib.pyplot as plt

x= {"사과": 100, "귤": 80, "호박": 60, "수박": 40}
plt.bar(x.keys(), x.values())
# output: UserWarning: Glyph 49324 (\N{HANGUL SYLLABLE SA}) missing from font(s) DejaVu Sans. func(*args, **kwargs)...
alt text
Blocks instead of Korean text

Fix
#

Change the font used by Matplotlib.

import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'AppleGothic' # for mac. For Windows, use 'Malgun Gothic'
plt.rcParams['axes.unicode_minus'] = False

x= {"사과": 100, "귤": 80, "호박": 60, "수박": 40}
plt.bar(x.keys(), x.values())
alt text
Korean texts are shown correctly
Robin G Lee
Author
Robin G Lee
A graduate student

Related