どうも、ちょげ(@chogetarou)です。
matplotlibでグラフのグラフが表示されているプロットエリアの背景色を変える方法を紹介します。
方法

matplotlibでグラフのプロットエリアの背景色を変えるには、pyplotのaxes()を使います。
まず、グラフを描画する前に、pyplotからaxes()を呼び出します。
pyplot.axes()の戻り値からset_facecolor()を呼び出します。
そして、set_facecolor()の引数に背景色を指定します。
import matplotlib.pyplot as plt
ax = plt.axes()
ax.set_facecolor(background_color)
上記の処理で、set_facecolor()の引数に指定した色が、グラフのプロットエリアの背景色になります。
使用例
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5, 6]
y = [10, 4, 6, 19, 15, 7]
ax = plt.axes()
ax.set_facecolor('yellow')
plt.plot(x, y)
plt.show()

コメント