Draw Japanese with matplotlib on Ubuntu

Confirm that Japanese fonts are included (TakaoP Gothic is used this time)

fc-list | grep Takao
/usr/share/fonts/truetype/fonts-japanese-gothic.ttf:Takao P Gothic,TakaoPGothic:style=Regular
/usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf:Takao P Gothic,TakaoPGothic:style=Regular

Set font

import matplotlib
from matplotlib.font_manager import FontProperties

font_path = '/usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf'
font_prop = FontProperties(fname=font_path)
matplotlib.rcParams['font.family'] = font_prop.get_name()

f1 = plt.figure()
af1 = f1.add_subplot(111)
af1.set_title(u'Take it')
af1.set_xlabel(u'Horizontal axis')
af1.plot([1, 2, 3, 4], label=u'Eh')
af1.plot([2, 3, 3, 2], label=u'Bee')
plt.legend()
plt.draw()

image

Delete cache when it doesn't work (super important)

rm ~/.cache/matplotlib/fontList.cache

Recommended Posts

Draw Japanese with matplotlib on Ubuntu
Japanese with matplotlib
[Python] Japanese localization of matplotlib on Ubuntu
Use matplotlib on Ubuntu 12 & Python
Set matplotlib font on ubuntu
Draw a loose graph with matplotlib
Mount S3 on Ubuntu with goofys
Multiple file processing with Kivy + Matplotlib + Draw Graph on GUI
Create SVG graph with matplotlib on heroku (displayed in Japanese)
Easy Japanese font setting with matplotlib
I couldn't input Japanese on Ubuntu 20.04
Easy to draw graphs with matplotlib
Draw Lyapunov Fractal with Python, matplotlib
Notes on doing Japanese OCR with Python
Draw shapes on feature layers with ArcPy
Write SVG graphs with matplotlib on heroku
Display Japanese graphs with VS Code + matplotlib
Draw hierarchical axis labels with matplotlib + pandas
[Python] Let's make matplotlib compatible with Japanese
Shebang on Ubuntu 20.04
Animation with matplotlib
Animation with matplotlib
Histogram with matplotlib
Animate with matplotlib
I can't install Dask with pip on Ubuntu
Draw a flat surface with a matplotlib 3d graph
Draw a graph with Japanese labels in Jupyter
[Ubuntu] Enables Japanese input with US keyboard layout
Build python environment with pyenv on EC2 (ubuntu)
Build Python3.5 + matplotlib environment on Ubuntu 12 using Anaconda
Drawing tips with matplotlib on the server side
[Python] How to draw multiple graphs with Matplotlib
[0] TensorFlow-GPU environment construction built with Anaconda on Ubuntu
Draw a graph with matplotlib from a csv file
Play with your Ubuntu desktop on your Raspberry Pi 4
Reverse proxy with Apache 2.4 on Ubuntu 19.10 Eoan Ermine
Visualize grib2 on a map with python (matplotlib)
Draw a line / scatter plot on the CSV file (2 columns) with python matplotlib
Install TensorFlow on Ubuntu
2-axis plot with Matplotlib
Put Scipy + Matplotlib in Ubuntu on Vagrant and display the graph with X11 Forwarding
Japanese input with pyautogui
Draw an Earth-like flow animation with matplotlib and cartopy
Install PySide2 on Ubuntu
I made a Python3 environment on Ubuntu with direnv.
Install JModelica on Ubuntu
Heatmap with Python + matplotlib
Forcibly draw something like a flowchart with Python, matplotlib
Band graph with matplotlib
Speaking Japanese with OpenJtalk
Learn with Cheminformatics Matplotlib
Troublesome story when using Python3 with VScode on ubuntu
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Real-time drawing with matplotlib
Various colorbars with Matplotlib
build Python on Ubuntu
3D plot with matplotlib
Install Python 3.3 on Ubuntu 12.04
Dealing with pip and related installation errors on Ubuntu 18.04
Installing pyenv on ubuntu 16.04
Install Theano on Ubuntu 12.04