Python 3はUTF-8に対応しているので,日本語を含めて様々な文字を扱うことができる。しかし,matplotlibが既定で使うフォントが日本語を含まないフォントなので,グラフに日本語を使うと文字化けが発生し,文字の代わりに「豆腐」と呼ばれる「□」が表示される。
import matplotlib.pyplot as plt
plt.figure()
plt.xlabel('x軸')
plt.ylabel('y軸')
plt.title('タイトル')
plt.show()
matplotlibの既定の設定ファイルの場所を探す。
import matplotlib as mpl
print(mpl.matplotlib_fname())
C:\Users\eno\Miniconda3\lib\site-packages\matplotlib\mpl-data\matplotlibrc
import matplotlib
matplotlib.matplotlib_fname()
'C:\\Users\\eno\\.matplotlib\\matplotlibrc'
カーネルを再起動してもう一度プロットする。
import matplotlib.pyplot as plt
plt.figure()
plt.xlabel('x軸')
plt.ylabel('y軸')
plt.title('タイトル')
plt.show()