Install Japanese fonts such as IPA in advance. After downloading the zip, unzip it and right-click the .ttf file to install it. Information-technology Promotion Agency, Japan
The default font, sans-serif
, must be changed to ʻIPA Gothic, ʻIPA Mincho
, and so on.
There are two ways to do it
matplotlibrc is a matplotlib configuration file.
ʻExecuted when import matplotlibis performed. If you save it in the directory under
~ / .matplotlib with the name
matplotlibrc, it will be read when you import
matplotlib`.
Find out which rc config file is valid with the following code.
Find out which matplot librc is valid
>>> import matplotlib as mpl
>>> mpl.matplotlib_fname()
'C:\\Users\\python\\.matplotlib\\matplotlibrc'
The contents to be written are as follows. As I wrote at the beginning, in this case IPA Mincho is installed. You should be able to use other fonts. Look up the name.
~/.matplotlib/matplotlibrc
font.family : IPAMincho
If seaborn
is running at the same time as matplotlib.pyplot
at startup, also perform the following operations.
When importing seaborn, the default value font
of the set function of rcmod.py
in C: \ tools \ Anaconda3 \ Lib \ site-packages \ seaborn \ rcmod.py
is" sans-serif ". Change from to "IPA Mincho" etc.
def set(context="notebook", style="darkgrid", palette="deep",
font="IPAMincho", font_scale=1, color_codes=False, rc=None):
Change font at the beginning of the script(matplotlib.pyplot)
import matplotlib as mpl
mpl.rcParameters['font.family'] = 'IPAMincho'
Change font at the beginning of the script(seaborn)
sns.set(font=['IPAMincho'])
If the settings are correct but something goes wrong, updating the font cache with the following command may work.
import matplotlib as mpl
matplotlib.font_manager._rebuild()
Reference: Updating the Matplotlib Font Cache
Recommended Posts