Skip to article frontmatterSkip to article content

Matplotlibで日本語表示

matplotlib-fontjaで日本語表示に対応する.

matplotlibで日本語フォントを使う準備

# matplotlibで日本語フォントを使う準備1
# matplotlib-fontjaのインストール

!pip install matplotlib-fontja
# matplotlibで日本語フォントを使う準備2
# matplotlibとともにjapanize_matplotlibを読み込む

import matplotlib.pyplot as plt
import matplotlib_fontja

matplotlib_fontjaの読み込みはmatplotlibの後に行う必要がある.

離散指数増殖モデル

# 離散指数増殖モデル
a = 0.1
x = 1
t = 0

t_list = [t]
x_list = [x]
for i in range(100):
    t = t + 1
    x = x + a * x

    t_list.append(t)
    x_list.append(x)
# タイトル・軸ラベル(日本語)
plt.plot(t_list, x_list)
plt.title("指数増殖")
plt.xlabel("時刻 (t)")
plt.ylabel("集団サイズ (x)")
<Figure size 640x480 with 1 Axes>