[PYTHON] Resolve garbled Japanese characters in matplotlib of Jupyter Notebook on Docker

Introduction

Every time I use jupyter in various environments, I feel that I am suffering from the problem of garbled Japanese characters. This time there was no solution for Don Pisha, so I will record it.

Overview

Resolve garbled Japanese characters in matplotlib of Jupyter Notebook on Docker. (Proceed by adding to the Dockerfile.)

point

  1. Check the location of the font file
  2. Font download
  3. Place the font file in the confirmed location
  4. Check the location of the matplotlib configuration file
  5. Set the matplotlib font
  6. Check cache location
  7. Delete cache

work

1. Check the location of the font file

Confirmed on jupyter.


import matplotlib.font_manager as fm
fm.findSystemFonts()

['/ File storage PATH / Somehow .ttf', You should see something like'/ file storage PATH / something .ttf']. (Use in 3)

2. Font download

Download "IPAex Gothic" from IPAex Font. Put ipaexg.ttf in the same directory as Dockerfile.

3. Place the font file in the confirmed location

Added to Dockerfile.

COPY ipaexg.ttf  /File storage PATH (check with 1)/

4. Check the location of the matplotlib configuration file

Confirmed on jupyter.


import matplotlib
matplotlib.matplotlib_fname()

You should see something like'/ settings storage PATH / matplotlib / matplotlibrc'. (Use in 5)

5. Set the matplotlib font

Added to Dockerfile.

RUN echo 'font.family : IPAexGothic' >> /Setting storage PATH/matplotlib/matplotlibrc

6. Check cache location

Confirmed on jupyter.


import matplotlib as mpl
mpl.get_configdir()

You should see something like'/ cache PATH / .cache / matplotlib'. (Used in 6)

7. Delete cache

!rm -r /Cache storage PATH/.cache/matplotlib

end

スクリーンショット 2020-07-11 1.27.04.png

Recommended Posts

Resolve garbled Japanese characters in matplotlib of Jupyter Notebook on Docker
About the garbled Japanese part of pandas-profiling in Jupyter notebook
Eliminate garbled Japanese characters in matplotlib graphs in Cloud Pak for Data Notebook
Eliminate garbled Japanese characters in Python library matplotlib and NetworkX
Unable to display tensorboard in jupyter notebook on docker (solved)
Write charts in real time with Matplotlib on Jupyter notebook
GPU check of PC on jupyter notebook
[Python] Japanese localization of matplotlib on Ubuntu
Install matplotlib and display graph on Jupyter Notebook
Browser specification of Jupyter Notebook in Windows environment
Fix garbled characters when handling Japanese in Requests
Try Apache Spark on Jupyter Notebook (on local Docker
The story of launching python2.x jupyter notebook using docker (crushed on Saturday and Sunday)
EC2 provisioning with Vagrant + Jupyter (IPython Notebook) on Docker
How to eliminate garbled characters in matplotlib output image
[EC2] Prevent garbled Japanese characters on selenium (noto compatible)
Eliminate garbled Japanese characters in JSON data acquired by API.
[Memo] Display Jupyter Notebook on PC in monospaced font (Mac)
Count the number of characters in the text on the clipboard on mac
Create SVG graph with matplotlib on heroku (displayed in Japanese)
View dynamic graphs in Jupyter notebook. (Inline display of D3.js)
Japanese display of matplotlib, seaborn
Multiprocessing error in Jupyter Notebook
High charts on Jupyter notebook
View PDF on Jupyter Notebook
Run IPython Notebook on Docker
Run Jupyter Notebook on windows
Day 65 I installed matplotlib to draw graphs on my Jupyter notebook.
How to resolve ModuleNotFoundError: No module named XXX in Jupyter Notebook
Git management of Jupyter notebook (ipynb) differences in easy-to-read with JupyterLab
Real-time display of video acquired from webcam on Jupyter notebook (Python3)
Formatting with autopep8 on Jupyter notebook
Draw Japanese with matplotlib on Ubuntu
Completion of docker command on Linux
Generate Jupyter notebook ".ipynb" in Python
Run Matplotlib on a Docker container
Run azure ML on jupyter notebook
View graphs inline in Jupyter Notebook
Make matplotlib Japanese compatible in 3 minutes
Try running Jupyter Notebook on Mac
I wanted to use jupyter notebook with docker in pip environment (opticspy)
Understand how to display images on Jupyter (utilization of imshow / matplotlib of OpenCV)
How to deal with garbled characters in json of Django REST Framework