[PYTHON] Japanese with matplotlib

Sometimes I need to use Japanese in matplotlib.pyplot, every time that? Is it fontproperties? Is it a prop? property? So, if you try to organize it, only the legend is prop, and the rest is font properties. (There is no property ...)

For your reference.

fontproperties.png

japanese_in_matplotlib.py


# -*- coding: utf-8 -*-

import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties

fp = FontProperties(fname=r'C:\WINDOWS\Fonts\YuGothic.ttf', size=14)

plt.bar([1, 2], [5, 10], 0.25)
plt.bar([1.25, 2.25], [4, 8], 0.25, color='darkorange')
plt.xlim((0.75, 2.75))
plt.ylim((0, 12))
plt.ylabel(u'Axis label is fontproperties=fp', fontproperties=fp)
plt.xticks([1.25, 2.25], [u'The scale is', 'fontproperties=fp'], fontproperties=fp)
plt.title(u'The title is fontproperties=fp', fontproperties=fp)
plt.text(2.125, 10, u'The text is\nfontproperties=fp', fontproperties=fp,
         ha='center')
plt.annotate(u'Annotation is\nfontproperties=fp', xy=(1.125, 5), xytext=(1.3, 8),
             fontproperties=fp, arrowprops=dict(facecolor='k', shrink=0.05))
plt.legend([u'The legend is', 'prop=fp'], prop=fp, loc='upper left')
# plt.show()
plt.savefig('fontproperties.png', bbox_inches='tight')
plt.close()

Recommended Posts

Japanese with matplotlib
Draw Japanese with matplotlib on Ubuntu
Animation with matplotlib
Easy Japanese font setting with matplotlib
Animation with matplotlib
Histogram with matplotlib
Animate with matplotlib
Display Japanese graphs with VS Code + matplotlib
2-axis plot with Matplotlib
Japanese input with pyautogui
Heatmap with Python + matplotlib
Band graph with matplotlib
Speaking Japanese with OpenJtalk
Real-time drawing with matplotlib
Various colorbars with Matplotlib
3D plot with matplotlib
Adjust axes with matplotlib
Send Japanese email with Python3
Japanese display of matplotlib, seaborn
Graph drawing method with matplotlib
Graph Excel data with matplotlib (2)
Stackable bar plot with matplotlib
Japanese morphological analysis with Python
Gradient color selection with matplotlib
Animate multiple graphs with matplotlib
Create SVG graph with matplotlib on heroku (displayed in Japanese)
Create plot animation with Python + Matplotlib
A python graphing manual with Matplotlib.
Inference & result display with Tensorflow + matplotlib
Japaneseize Matplotlib with Alpine using Docker
[Python] font family and font with matplotlib
Draw a loose graph with matplotlib
[Natural language processing] Preprocessing with Japanese
Versatile data plotting with pandas + matplotlib
Japanese speech synthesis starting with Tacotron2
Using Japanese with Rodeo's IPython @ Windows
Heatmap with Dendrogram in Python + matplotlib
I can't use Japanese with pyperclip
Speak Japanese text with OpenJTalk + python
Make matplotlib Japanese compatible in 3 minutes
Easy to draw graphs with matplotlib
Continuously color with matplotlib scatter plot
Draw Lyapunov Fractal with Python, matplotlib
When matplotlib doesn't work with python2.7
Lognormal probability plot with Python, matplotlib
Easy animation with matplotlib (mp4, gif)
Write a stacked histogram with matplotlib
Implement "Data Visualization Design # 2" with matplotlib
Matplotlib memorandum
Japanese settings for matplotlib and Seaborn axes
How to title multiple figures with matplotlib
[Python] Set the graph range with matplotlib
Adjust the spacing between figures with Matplotlib
[Note] Japanese characters are garbled with atom-runner
Align the size of the colorbar with matplotlib
Generate Japanese test data with Python faker
Matplotlib gallery
Matplotlib memo
Put Japanese fonts in images with Colaboratory
Download Japanese stock price data with python
Notes on doing Japanese OCR with Python