How to use Japanese in Matplotlib

Install the japanize-matplotlib module.

pip install japanize-matplotlib

By importing the module, you can use Japanese in the title and axis labels.

import numpy as np
import matplotlib.pyplot as plt
import japanize_matplotlib

time = np.arange(0, 10, 0.1)
amplitude = np.sin(time)

plt.plot(time, amplitude)
plt.title("図のタイトル", fontsize=14)
plt.xlabel("X軸のラベル名", fontsize=14)
plt.ylabel("Y軸のラベル名", fontsize=14)
plt.savefig("sine_wave.png")

References

Comments

Copied title and URL