There are some similar articles on Qiita, but it was difficult to understand, so I will summarize them for myself.
As for the situation, the default font of matplotlib on macOS Sierra does not support Japanese, so I want ▫︎▫︎▫︎ (it seems to be tofu) to display Japanese on the graph for the time being!
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.
Shazam!
Recommended Posts