考虑这个 MWE,
from matplotlib import pyplot
pyplot.style.use('classic')
pyplot.rcParams.update( {
'text.usetex': True,
"font.family": "serif",
'text.latex.preamble': r'\usepackage{amsmath, amssymb, mlmodern}', } )
import numpy
fig, ax = pyplot.subplots(3,3)
fig.tight_layout()
fig.subplots_adjust(hspace=0.1, wspace=0.1,
left=0.09, right=.95, top=.95, bottom=.09)
x = numpy.linspace(0, 8, 100)
for i in range(3):
for j in range(3):
ax[i,j].plot(x, numpy.sin((1+j)*x+numpy.pi*i), )
ax[i,j].grid(which='both') # <----------------- I added grid here
if i!=2: ax[i,j].set_xticks([])
if j==1: ax[i,j].set_yticks([])
if j==2: ax[i,j].yaxis.tick_right()
ax[0,0].set_ylabel('$\phi=0$')
ax[1,0].set_ylabel('$\phi=\pi$')
ax[2,0].set_ylabel('$\phi=2\pi$')
ax[2,0].set_xlabel('$f = 1$')
ax[2,1].set_xlabel('$f = 2$')
ax[2,2].set_xlabel('$f = 3$')
pyplot.savefig('waves.png')
我不明白为什么matplotlib有(0,0)和(0,2)轴的网格线,(0,1)轴的垂直网格线,(1,0)轴的水平网格线,(1, 2)、(2,0) 和 (2,2),并且轴 (1,1) 和 (2,1) 没有网格线。
如何确保所有轴的网格类似于 (0,0)?谢谢你。