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.
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