+2 votes
in Programming Languages by (26.1k points)
I do not like the default color of the grid in matplotlib plot. How can I change it?

1 Answer

+3 votes
by (33.0k points)
selected by
Best answer

The grid() function of matplotlib supports keyword arguments (**kwargs) to define the line properties of the grid, e.g.:

grid(color='r', linestyle='-', linewidth=2)

So, you need to use the color argument to set the color of your choice.

Here is a sample code:

import matplotlib.pyplot as plt

plt.grid(which='both', axis='both', linestyle='--', color='lavender')