[PYTHON] Make matplotlib Japanese compatible in 3 minutes

Handle Japanese with matplotlib in python

procedure

  1. Go to http://ipafont.ipa.go.jp/old/ipafont/download.html and download the 4 typeface pack of TTF files.

font name family
ipagp.ttf IPAPGothic [sans-serif]
ipamp.ttf IPAPMincho [sans-serif]
ipam.ttf IPAMincho [sans-serif]
ipag.ttf IPAGothic [sans-serif]

It seems that it corresponds like this (see http://qiita.com/kshigeru/items/0cfc0778bab197687967), so

plt.rcParams['font.family'] = 'IPAPGothic' #Set the entire font

And. Also, let's set the size of the graph and the font size on the vertical and horizontal axes:

plt.rcParams["figure.figsize"] = [20, 12] #Specify the size of the graph
plt.rcParams['font.size'] = 20 #Set font size default: 12
plt.rcParams['xtick.labelsize'] = 15 #Font size on the horizontal axis
plt.rcParams['ytick.labelsize'] = 15 #Font size on the vertical axis

3.

~ / .matplotlib / fontList.py3k.cache looks like a font cache file, so if you run it (on Jupyter notebook) with rm -f ~ / .matplotlib / fontList.py3k.cache

%matplotlib inline
import matplotlib.pyplot as plt

plt.rcParams['font.family'] = 'IPAPGothic' #Set the entire font

plt.rcParams["figure.figsize"] = [20, 12]
plt.rcParams['font.size'] = 20 #Set font size default: 12
plt.rcParams['xtick.labelsize'] = 15 #Font size on the horizontal axis
plt.rcParams['ytick.labelsize'] = 15

# test
df = DataFrame(np.arange(0, 12).reshape(6, -1), columns = ['start','the end'])
df.plot(kind = 'bar', x = 'start', y = 'the end').set(xlabel = 'start', ylabel = 'the end')
# plt.show()  # %Since matplotlib inline is specified, it may or may not be present.

d.png

Shazam!

Recommended Posts

Make matplotlib Japanese compatible in 3 minutes
[Python] Let's make matplotlib compatible with Japanese
Japanese with matplotlib
How to make Linux compatible with Japanese keyboard
Put matplotlib in Centos7.
Learn Pandas in 10 minutes
View images in Matplotlib
2D plot in matplotlib
Make Japanese into Romaji
Understand in 10 minutes Selenium
Japanese output in Python
Selenium running in 15 minutes
English PDF in Japanese
Create SVG graph with matplotlib on heroku (displayed in Japanese)
Make the function of drawing Japanese fonts in OpenCV general
I wrote python in Japanese
Japanese display of matplotlib, seaborn
Embed matplotlib graphs in Tkinter
Don't make test.py in Python!
Make a bookmarklet in Python
Make python segfault in 2 lines
Display Japanese in JSON file
I understand Python in Japanese!
Start in 5 minutes GIMP Python-Fu
Get Japanese synonyms in Python
[Tutorial] Make a named entity extractor in 30 minutes using machine learning
Resolve garbled Japanese characters in matplotlib of Jupyter Notebook on Docker