I am having difficult trying to get minor gridlines to appear on a plot. I have seen a couple of SO questions on this, this one suggesting two grid objects (one for major and one for minor) and this one suggesting also adding minorticks_on
.
For some reason the minor gridlines are still not appearing when I use the code below, can anyone shed any light please:
from __future__ import division
from matplotlib import pyplot as plt
from math import log, sqrt
x = range(1, 20)
x_lin = x
x_log = [log(i) for i in x]
x2 = [sqrt(i) for i in x]
x2_exp = x
ax = plt.subplot(1,1,1)
p1 = ax.plot(x, x_lin, 'g--', label='linear', linewidth=2)
p2 = ax.plot(x, x_log, 'b-', label='log', linewidth=3)
p3 = ax.plot(x2, x2_exp, 'r-', label='exp', linewidth=3)
l1 = ax.legend()
g1 = ax.grid(b=True, which='both', color='k', linestyle='-')
g2 = ax.grid(b=True, which='minor', color='k', linestyle='--')
ax.minorticks_on
plt.show()
Here is what I am getting: