There are many ways. The most directly related to the style of code you have will be
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10)
y = np.linspace(0, 10)
plt.figure(facecolor="white")
plt.plot(x, y)
plt.show()

This can also be set for all graphs in the session by doing
import matplotlib as mpl
mpl.rc("figure", facecolor="white")
Or for all graphs in all sessions, setting figure.facecolorto a file matplotlibrc.
source
share