Hi all. When my matplotlibrc contains
axes.grid : True
Then the following plot does not show a grid:
from matplotlib import pyplot as plt
import matplotlib.ticker as ticker
import numpy as np
x = np.geomspace(0.001,5,101)
y = 10**(-0.2-0.05*(np.log10(x)+0.5)**2)
plt.figure(figsize=[5,5])
ax = plt.gca()
plt.plot(x,y)
plt.xscale('log')
plt.yscale('log')
plt.xlabel('$x$')
plt.ylabel('$y$')
yticks = [0.2,0.3,0.4,0.5,0.6] # should not need to be set!
ax.yaxis.set_major_locator(ticker.FixedLocator(yticks)) # why so complicated?
plt.grid()
I find this lack of grid, quite puzzling.
But if I remove the line from my matplotlibrc, then the plot comes out with the proper grid. Is there a way to keep axes.grid : True
in my matplotlibrc and be able to see the grid? For example
plt.grid(axis='both')
does not show the grid (with the line in my matplotlibrc).
I also added comments to complain that setting ticks in matplotlib is more complicated than in other plotting languages. For one, if the log axis has a narrow range, matplotlib should default to choosing major ticks that are not decades.