Since matplotlib does not support Japanese with standard fonts ...
The characters will be garbled like this. this Let's make it like this.# OS version
ProductName: Mac OS X
ProductVersion: 10.15.6
BuildVersion: 19G2021
# Python version
Python 3.8.5
# matplotlib version
matplotlib==3.3.0
First, download the font as you like. This time, we will use IPA Font.
Move the ttf file to the matprotlib font folder. The path depends on the environment, but refer to the following.
/usr/local/lib/python3.8/site-packages/matplotlib/mpl-data/fonts/ttf
If you can't find the lib (library) folder, you can select the library from the Go tab in the Finder or make it always visible from the View options on the View tab. You should reach such a folder.
Open matplotlibrc in the folder (mpl-data folder) two higher than the ttf folder.
Look for the description "# font.family sans-serif" ... Add "font.family IPAex Gothic" to the line below.
This completes the settings!
Check that the font is displayed normally.
If the following error occurs
UserWarning: findfont: Font family ['IPAexGothic'] not found. Falling back to DejaVu Sans.
It is possible that the font cache remains.
Delete "fontlist ***. Json" in the /Users/username/.matplotlib folder and Please restart Jupyter Notebook. The .matplotlib folder is a hidden folder, so if you don't see it, try "Shift + Cmd +. (Dot)".
The Japanese localization method in the Anaconda environment will come out if you google, but since there was no example in the pure Python environment, I tried to summarize it based on my own experience. I hope you find it useful.
Recommended Posts