Matplotlib の日本語表示

モジュールのインポート

Matplotlib の日本語表示は,
https://pypi.org/project/japanize-matplotlib/
より,インストール(pip install japanize-matplotlib)して,
import numpy as np
import matplotlib.pyplot as plt
import japanize_matplotlib
ただし,SciencePlotsは対応していない.

プロット

x = np.array([0,1,2,3,4,5,6])
x = x*np.pi/6
x
array([0.        , 0.52359878, 1.04719755, 1.57079633, 2.0943951 ,
       2.61799388, 3.14159265])
通常のプロットに加えて,棒グラフ
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.bar.html
散布図
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.scatter.html
を重ねて書くことができ,
plt.rcParams['font.size']=14
fig, ax = plt.subplots()# figure, axes
ax.bar(x,np.sin(x), label=r'$\sin x$', color='y')
ax.plot(x,x, label='$x$-$x$', marker='o')
ax.scatter(x,np.sin(x), label=r'$\sin x$', color='r')
ax.set_xlabel('$x$')
ax.set_ylabel('$F(x)$')
ax.set_yticks([0,1,2,3])
ax.set_title('例題')
ax.grid()
ax.legend()
fig.savefig("japanize_matplotlib_ex1.pdf")
plt.show()

もちろん,別々に並べても書け,
xx = np.linspace(0.0, np.pi, 101)
plt.rcParams['font.size']=12
fig, ax = plt.subplots(2,2, figsize=(12,9))# figure, axes
ax[0,0].bar(x,np.sin(x), width=0.45, color='y')
ax[0,0].set_title(r'$\sin x$')
ax[0,1].plot(x,x, marker='o')
ax[0,1].set_title('$x$-$x$')
ax[1,0].scatter(x,np.sin(x), color='r')
ax[1,0].set_title(r'$\sin x$')
ax[1,1].plot(xx,np.sin(2*xx))
ax[1,1].set_title(r'$\sin 2x$')
fig.savefig('japanize_matplotlib_ex2.pdf')
plt.show()