[PYTHON] Seaborn, matplotlib garbled characters resolved in Windows10, Anaconda virtual environment

Garbled Japanese characters when drawing graphs

When I tried to display Japanese in the graph, the characters became garbled and I was quite addicted to it, so as a memorandum.

When using a virtual environment with Anaconda, it will be reset to "Every environment".

environment

Without Japanese font

Characters are garbled with the display of missing from current font.

mojibake.png

Motivation for posting

The font used to eliminate garbled characters may be MS Gothic, but it seems that the license-free font ʻIPAex Gothic, which can also be used on Linux, is often used. In some past reference articles, past fonts such as ʻIPAP Gothic were used, so I was addicted to writing with reference to that.

Obtaining and implementing Japanese fonts

It can be obtained from the IPA site. In 2020 Oct, ʻIPAex font v4.0.1` seems to be the latest. Follow the procedures such as terms of use to download and unzip.

ipa.png

Copy ttf file to the following folder

C: \ Users \ [your account] \ Anaconda3 \ envs \ [virtual environment name you want to use] \ Lib \ site-packages \ matplotlib \ mpl-data \ fonts \ ttf

File rewriting

Open the matplotlibrc file in the following folder with Notepad etc.

C: \ Users \ [your account] \ Anaconda3 \ envs \ [virtual environment name you want to use] \ Lib \ site-packages \ matplotlib \ mpl-data

Around line 250

  1. Add ʻIPAexGothic,to # font.family :. (It seems that the defaultsans-serif` can be deleted.) Also, change the name as appropriate depending on the font used.
  2. Added ʻIPAex Gothic,` to # font.serif:.
  3. Save your changes

font.png

Clear cache

  1. Put the cache file fontlist-vXXX.json in C: \ Users \ [your account] \ .matplotlib to the Trash
  2. Copy the modified file matplotlibrc file
  3. Ready cache3.png

Check if the garbled characters have been resolved

Reboot the virtual environment mojibakefinlal.png

The garbled characters have been successfully resolved.

Recommended Posts

Seaborn, matplotlib garbled characters resolved in Windows10, Anaconda virtual environment
Various Anaconda settings in Windows 10 environment
Creating a virtual environment in an Anaconda environment
Python garbled in Windows + Git Bash environment
Unable to import packages installed in virtual environment with Anaconda on Windows 10
Error running Jupyter Notebook in Anaconda virtual environment
virtualenvwrapper in windows environment
virtual environment in python
Create an Anaconda virtual environment in your project folder
How to eliminate garbled characters in matplotlib output image
Command line collection for using virtual environment in Anaconda
Use Anaconda in pyenv environment
Build an Anaconda virtual environment
Eliminate garbled Japanese characters in Python library matplotlib and NetworkX
Double-click ipynb in windows + anaconda environment to open with jupyter-notebook
[Anaconda] Activate the virtual environment
Resolve garbled Japanese characters in matplotlib of Jupyter Notebook on Docker
Environment construction of TensorFlow + JupyterNotebook + Matplotlib on Windows version Anaconda (August 2017 version)
Error in ordinal number when importing Numpy in Anaconda environment of Windows
Anaconda python environment construction on Windows 10
Install scrapy in python anaconda environment
install tensorflow in anaconda + python3.5 environment
UnicodeDecodeError occurs in pip (Windows environment)
Using graph drawing using Python's Matplotlib + Seaborn on Windows, a non-Python execution environment
Eliminate garbled Japanese characters in matplotlib graphs in Cloud Pak for Data Notebook
Install Django in a pipenv virtual environment
Using venv in Windows + Docker environment [Python]
[5 steps] Apply anaconda virtual environment to VScode
[Python] Create a virtual environment with Anaconda
Effortlessly vscode + venv virtual environment (Windows) memo
Creating a python virtual environment on Windows
Set up Pipenv in Pycharm in Windows environment
Building scikit-learn in Windows 10 environment using Pycharm
tensorflow does not enter in windows + anaconda.
Windows Qt5.4 Python3.4 QProcess Japanese garbled characters
I started Node.js in a virtual environment
How to install the deep learning framework Tensorflow 1.0 in the Anaconda environment of Windows