The following code uses matplotlib.pyplot.grid
to turn on the grid and set the grid properties (line color, style and width), and then uses plt.gca().patch.set_facecolor('0.8')
to change the color of the axes (I don't I am sure that there is, but for this there should be a convenient function). The argument to patch.set_facecolor
is any matplotlib color .
import numpy import matplotlib.pyplot as plt x = numpy.random.rand(10) x = numpy.random.rand(10) plt.plot(x, y, 'o') plt.grid(True, color='w', linestyle='-', linewidth=2) plt.gca().patch.set_facecolor('0.8') plt.show()
Result
source share