[PYTHON] Japanese display of matplotlib, seaborn

Japanese display of graphs made with python

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

Play with ~ / .matplotlib / matplotlibrc

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

Note startup.ipy

If seaborn is running at the same time as matplotlib.pyplot at startup, also perform the following operations.

seaborn settings

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):

Declaration of font change at the beginning of the script

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'])

Font cache update

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

Japanese display of matplotlib, seaborn
[Seaborn] Display Japanese (change font)
Japanese settings for matplotlib and Seaborn axes
External display of matplotlib diagrams using tkinter
Display Japanese graphs with VS Code + matplotlib
About Japanese fonts of matplotlib (for Mac)
Japanese with matplotlib
[Python] Japanese localization of matplotlib on Ubuntu
(Mac) How to display Japanese with Matplotlib and Seaborn At MacOS Sierra
Japanese localization of Pycharm
Display of fractions (list)
Installation of matplotlib (Python 3.3.2)
Japanese localization setting of PyCharm
About Japanese path of pyminizip
behavior of matplotlib: histogram normed
Formatted display of pandas DataFrame
About Japanese support of cometchat
Real-time graph display by matplotlib
Japanese translation of sysstat manual
Change the style of matplotlib
Display Japanese in JSON file
Japanese translation of Linux manual
Grid display of double plots (left and right vertical axes) (matplotlib)
Resolve garbled Japanese characters in matplotlib of Jupyter Notebook on Docker
Installation of SciPy and matplotlib (Python)
Inference & result display with Tensorflow + matplotlib
Japanese translation of the e2fsprogs manual
Draw Japanese with matplotlib on Ubuntu
Waveform display of audio in Python
Installation of Python, SciPy, matplotlib (Windows)
Topic extraction of Japanese text 1 Basics
Easy Japanese font setting with matplotlib
Japanese translation of the man-db manual
Separate display of Python graphs (memo)
Make matplotlib Japanese compatible in 3 minutes
Appropriate Japanese translation of pytorch tensor_tutorial
Unravel the mystery of matplotlib specgram
matplotlib log scale display and grid display
About the size of matplotlib points
Japanese translation of the util-linux manual
Japanese translation of the iproute2 manual
[Python] How to specify the window display position and size of matplotlib
Adjust the bin width crisply and neatly with the histogram of matplotlib and seaborn
Understand how to display images on Jupyter (utilization of imshow / matplotlib of OpenCV)