为什么Matplotlib中的对数图中只有y轴的小刻度?

为什么Matplotlib中的对数图中只有y轴的小刻度?,matplotlib,plot,loglog,Matplotlib,Plot,Loglog,我试图在matplotlib中绘制一个非常简单的日志图。但是,似乎我可以在y轴上获得小刻度,但由于某些matplotlib原因,在x轴上没有。我希望在所有轴(底部、左侧、右侧和顶部)上都有记号,并且在x轴(顶部和底部)上有小记号 以下是我目前拥有的代码:: import math import numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import FormatStrFormatter from matp

我试图在matplotlib中绘制一个非常简单的日志图。但是,似乎我可以在y轴上获得小刻度,但由于某些matplotlib原因,在x轴上没有。我希望在所有轴(底部、左侧、右侧和顶部)上都有记号,并且在x轴(顶部和底部)上有小记号

以下是我目前拥有的代码::

import math
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter
from matplotlib.ticker import ScalarFormatter
from matplotlib import colors as mcolors
from matplotlib import gridspec

plt.rcParams.update({'font.size': 14})
plt.clf()
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2,2, sharex=True, sharey=True, gridspec_kw = {'wspace':0, 'hspace':0})

xmin =   0.006  
xmax = 70.00    
ymin =  0.0003  
ymax = 4.00 

ax1.set_xlim([xmin,xmax])
ax2.set_xlim([xmin,xmax])
ax3.set_xlim([xmin,xmax])
ax4.set_xlim([xmin,xmax])
ax1.set_xscale('log')
ax2.set_xscale('log')
ax3.set_xscale('log')
ax4.set_xscale('log')
ax1.set_ylim([ymin,ymax])
ax2.set_ylim([ymin,ymax])
ax3.set_ylim([ymin,ymax])
ax4.set_ylim([ymin,ymax])
ax1.set_yscale('log')
ax2.set_yscale('log')
ax3.set_yscale('log')
ax4.set_yscale('log')

ax1.plot(log_wavelength, t, alpha=0.75, color='black')
ax2.plot(log_wavelength, x, alpha=0.75, color='red')
ax3.plot(log_wavelength, y, alpha=0.75, color='green')
ax4.plot(log_wavelength, z, alpha=0.75, color='cyan')

ax1.minorticks_on()
ax2.minorticks_on()
ax3.minorticks_on()
ax4.minorticks_on()

ax1.tick_params(axis='both', which='minor', length=4, color='k')
ax2.tick_params(axis='both', which='minor', length=4, color='k') 
ax3.tick_params(axis='both', which='minor', length=4, color='k')
ax4.tick_params(axis='both', which='minor', length=4, color='k')

ax.minorticks_on()不工作有什么原因吗?

您可以使用勾选参数进行更好的控制:

ax1.tick_params(axis='both', which='both', direction='in', top='on')
这是一个相当有用的函数,例如,如果您只想在图形窗口的边界外部设置记号:

ax1.tick_params(axis='both', which='both', direction='in', top='on', bottom='off', left='on', right='off')
ax2.tick_params(axis='both', which='both', direction='in', top='on', bottom='off', left='off', right='on')
ax3.tick_params(axis='both', which='both', direction='in', top='off', bottom='on', left='on', right='off')
ax4.tick_params(axis='both', which='both', direction='in', top='off', bottom='on', left='off', right='on')
您甚至可以通过设置“长度”和“宽度”参数来更改记号长度/宽度,尽管您可能希望将“which”更改为“minor/major”以单独调整它们。此外,您还可以从此处更改标记标签字体大小。e、 g

ax1.tick_params(axis='both', which='major', direction='in', length=6, width=1, labelsize=8)

要回答您关于ax.minorticks_on()为什么不工作的问题:不知道。我对此进行了抗争,但失败了,最终决定改用tick_参数……这是一条路。

fyi您的代码抛出了这个错误:
NameError:name'log_wavelength'没有定义。
tick_参数有用吗?