我正在使用以下代码绘制数据:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
Ed={"vCs":-5811.63801749,"vSb":-5352.588077, "vCl":-5825.86517}
Eprist=-5793.09448
dCs=np.array([0.0,-0.41613239])
uCs=-46.77765971+dCs
dSb=np.array([0.0,-0.624198585])
uSb=-505.785546+dSb
dCl=np.array([0.0,-0.1387107967])
uCl=-32.79123908+dCl
dO2=np.array([0.0,0.5792])
uO2=-66.07463153+dO2
uO2=-66.07463153
EfCl_Cl=Ed["vCl"]-Eprist+uCl-uO2
EfSb_Cl=Ed["vSb"]-Eprist+uSb-uO2
EfCs_Cl=Ed["vCs"]-Eprist+uCs-uO2
EfCl=np.concatenate((EfCl_Cl,EfSb_Cl,EfCs_Cl))
fig, (ax1,ax2,ax3) = plt.subplots(1,3)
ax1.plot(dCs,EfCs_Cl,label="vCs",
color="black",linestyle="-.", marker='s')
ax2.plot(dSb,EfSb_Cl,label="vSb",
color="red",linestyle="--", marker='^')
ax3.plot(dCl,EfCl_Cl,label="vCl",
color="blue",linestyle=":", marker='o')
ax1.legend()
xlims=[[-0.7,0.05],[-0.7,0.05],[-0.3,0.05]]
xticks=[np.arange(-0.5,0.1,0.2),np.arange(-0.6,0.1,0.2),np.arange(0.0,-0.3,-0.1)]
minorxLocator = MultipleLocator(0.05)
minoryLocator = MultipleLocator(0.05)
i=0
for ax in (ax1,ax2):
ax.set_ylim([min(EfCl)-0.1,max(EfCl)+0.1])
ax.set_xlim(xlims[i])
ax.set_xticks(xticks[i])
ax.xaxis.set_minor_locator(minorxLocator)
ax.yaxis.set_minor_locator(minoryLocator)
i += 1
ax3.set_xlim(xlims[i])
ax3.set_xticks(xticks[i])
ax3.xaxis.set_minor_locator(minorxLocator)
ax3.yaxis.set_minor_locator(minoryLocator)
plt.show()
我得到了轴 1 和轴 2 上的小刻度的图表,直到 ax3 的范围。
但是,如果我注释该行: ax3.xaxis.set_minor_locator(minorxLocator) 我在轴 1 和 2 上得到正确的小刻度(但在轴 3 中显然没有小刻度),如图所示:
我怎样才能在所有轴上得到应有的小刻度?我正在使用 Spyder 进行绘图(尽管在终端上产生了相同的结果,并且版本为 3.7.6 python)