Displaying Japanese or CJK characters in matplotlib | Python | Jupyter Notebook

Ganesh Karki
1 min readDec 6, 2022

While working with Jupyter notebook, I came across a problem while showing Japanese characters using matplotlib.

Errors

If you too are getting similar errors the below solution will work.

UserWarning: Glyph 12464 (\N{KATAKANA LETTER GU}) missing from current font.
fig.canvas.print_figure(bytes_io, **kw)
UserWarning: Glyph 26085 (\N{CJK UNIFIED IDEOGRAPH-65E5}) missing from current font.
fig.canvas.print_figure(bytes_io, **kw)
UserWarning: Glyph 12395 (\N{HIRAGANA LETTER NI}) missing from current font.
fig.canvas.print_figure(bytes_io, **kw)
UserWarning: Glyph 12599 (\N{HANGUL LETTER TIKEUT}) missing from current font.
fig.canvas.print_figure(bytes_io, **kw)

Solution:

Simply override the font family with a font that supports CJK characters (Chinese, Japanese, and Korean languages characters) for plotting charts

import matplotlib
# Override the font-family which supports CJK characters
matplotlib.rcParams['font.family'] = 'Hiragino sans'

A sample jupyter notebook’s cell

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
# Override the font-family which supports CJK characters
matplotlib.rcParams['font.family'] = 'Hiragino sans'


s = np.sin(np.pi*np.arange(0.0, 10.0, 0.05))
t = plt.plot(s, color=”r”)
plt.title(“ TEST グラフ”)
plt.show()

--

--