How can I fill a matplotlib grid?
The following code uses matplotlib.pyplot.grid
to turn on a grid and set the grid properties (line colour, style and width) and then uses plt.gca().patch.set_facecolor('0.8')
to change the axes color (I'm not sure if there is, but there must be convenience function to do this). The argument to patch.set_facecolor
is any matplotlib colour.
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()
The result is