I want to get both horizontal and vertical grid lines on my plot but only the horizontal grid lines are appearing by default. I am using a pandas.DataFrame from
According to matplotlib documentation, The signature of the Axes class grid() method is as follows:
Axes.grid(b=None, which='major', axis='both', **kwargs)
Turn the axes grids on or off.
whichcan be ‘major’ (default), ‘minor’, or ‘both’ to control whether major tick grids, minor tick grids, or both are affected.
axiscan be ‘both’ (default), ‘x’, or ‘y’ to control which set of gridlines are drawn.
So in order to show grid lines for both the x axis and y axis, we can use the the following code:
ax = plt.gca()
ax.grid(which='major', axis='both', linestyle='--')
This method gives us finer control over what to show for grid lines.