matplotlib tutorial (3) nitta@tsuda.ac.jp

Chapter 3: Using Japanese Font

  1. Download and unzip the Japanese Font, IPAex, distributed by IPA.
  2. Place ipaexg.ttf in the font folder of matplotlib.
  3. Delete the cache file of font.
  4. Restart the runtime.
  5. Set to read ipaexg.ttf in the setting file, matplotlibrc, of matplotlib. Specify plt.rcParams['font.family'] = 'IPAexGothic' in the python program.

3-1: Download and expand Japanese font.

There are several versions of the IPAex font. The latest version at the moment (2022/03/25) is Ver.004.01.

https://moji.or.jp/ipafont/ipaex00401/

This time, IPAex Gothic "ipaexg00401.zip" to download.

Official URL: https://moji.or.jp/wp-content/ipafont/IPAexfont/ipaexg00401.zip

mirror: http://nw.tsuda.ac.jp/python/matplotlib/ipaexg00401.zip

3-2: Examine the folder that stores the font.

Folders for storing fonts vary from system to system. The example code below is run on Google Colab.

If you install Anaconda to the path "D:\sys\Anaconda3" on Windows, here is an example of running jupyter notebook with the python virtual environment as "book3".

'D:\sys\Anaconda3\envs\book3\lib\site-packages\matplotlib\mpl-data\matplotlibrc'

3-3: Delete the font cache.

With Google Colab, find the location of the font cache by matplotlib.get_cachedir(). What should be deleted is the fontlist-vXXX.json file, but since it is troublesome, we will delete the entire folder this time.

Windows や Mac の Anaconda で jupyter を動作させている場合は、フォントキャッシュはmatplotlib.get_configdir() の下の fontlist-vXXX.json である。

3-4: Restart the runtime.

For Google Colab: Runtime → Restart Runtime.

For jupyter notebook on local PC: Kernel → Restart.

3-5: Use matplotlib by specifying font.family.

Immediately after restarting runtime, Execute the next cell.