Python 在所有日志子批次中设置小刻度

Python 在所有日志子批次中设置小刻度,python,matplotlib,subplot,loglog,Python,Matplotlib,Subplot,Loglog,我有一个对数比例的两个子图。我也想画出小刻度。尽管我应用了堆栈溢出的不同解决方案,但我的数字看起来并不像我想要的那样 我修改的一个解决方案来自以下代码: fig,((ax1,ax2))=plt.子批(1,2,figsize=(8,5),sharey=True) #第一个情节 ax1.loglog(PLOT1['X'],PLOT1['Y'],'o', markerfacecolor='red',markeredgecolor='red',markeredgewidth=1, markersize=

我有一个对数比例的两个子图。我也想画出小刻度。尽管我应用了堆栈溢出的不同解决方案,但我的数字看起来并不像我想要的那样

我修改的一个解决方案来自以下代码:

fig,((ax1,ax2))=plt.子批(1,2,figsize=(8,5),sharey=True)
#第一个情节
ax1.loglog(PLOT1['X'],PLOT1['Y'],'o',
markerfacecolor='red',markeredgecolor='red',markeredgewidth=1,
markersize=1.5,alpha=0.2)
ax1.set(xlim=(1e-4,1e4),ylim=(1e-8,1e2))
ax1.setxscale(“log”);ax1.设置刻度(“日志”)
ax1.xaxis.set\u major\u定位器(matplotlib.ticker.LogLocator(base=10.0,numticks=25))
ax1.yaxis.set\u major\u定位器(matplotlib.ticker.LogLocator(base=10.0,numticks=25))
locmaj=matplotlib.ticker.LogLocator(基数=10,numticks=25)
ax1.xaxis.set_major_定位器(locmaj)
locmin=matplotlib.ticker.LogLocator(基=10.0,子=0.2,0.4,0.6,0.8),numticks=25)
ax1.xaxis.set_minor_定位器(locmin)
ax1.xaxis.set_minor_格式化程序(matplotlib.ticker.NullFormatter())
locmaj=matplotlib.ticker.LogLocator(基数=10,numticks=25)
ax1.yaxis.set\u major\u定位器(locmaj)
locmin=matplotlib.ticker.LogLocator(基=10.0,子=0.2,0.4,0.6,0.8),numticks=25)
ax1.yaxis.set\u minor\u定位器(locmin)
ax1.yaxis.set\u minor\u格式化程序(matplotlib.ticker.NullFormatter())
ax1.设置标签('X值',fontsize=10,fontwweight='bold')
ax1.set_ylabel('Y值',fontsize=10,fontwweight='bold')
#情节2
ax2.loglog(PLOT2['X'],PLOT2['Y'],'o',
markerfacecolor='blue',markeredgecolor='blue',markeredgewidth=1,
markersize=1.5,alpha=0.2)
ax2.set(xlim=(1e-4,1e4),ylim=(1e-8,1e2))
ax2.xaxis.set\u major\u定位器(matplotlib.ticker.LogLocator(base=10.0,numticks=25))
ax2.yaxis.set\u major\u定位器(matplotlib.ticker.LogLocator(base=10.0,numticks=25))
locmaj=matplotlib.ticker.LogLocator(基数=10,numticks=25)
ax2.xaxis.set_major_定位器(locmaj)
ax2.yaxis.set\u major\u定位器(locmaj)
locmin=matplotlib.ticker.LogLocator(基=10.0,子=0.2,0.4,0.6,0.8),numticks=25)
ax2.xaxis.set_minor_定位器(locmin)
ax2.yaxis.set\u minor\u定位器(locmin)
ax2.xaxis.set_minor_格式化程序(matplotlib.ticker.NullFormatter())
ax2.yaxis.set\u minor\u格式化程序(matplotlib.ticker.NullFormatter())
ax2.set_xlabel('X值',fontsize=10,fontwweight='bold')
ax2.set_ylabel('Y值',fontsize=10,fontwweight='bold')
ax2.minorticks_on()
plt.show()
我得到的情节如下。如您所见,次刻度仅出现在ax1的x轴上

如何设置子批次和轴(x和y)中的副刻度


非常感谢。

您还需要为ax2轴设置定位器。非常重要的是,我修改了您为x和y轴(包括定位器)的ax2轴所做的一切。我做得对吗?ax2的y轴部件缺失。你说得对。谢谢你的帮助。但是,在我的Jupyter笔记本上,绘图仍然是一样的。哦,删除行
ax2.minorticks\u on()
。它不应该在链接的解决方案中,对吗?