Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 设置xticklabel与旧xtick重叠_Python_Matplotlib - Fatal编程技术网

Python 设置xticklabel与旧xtick重叠

Python 设置xticklabel与旧xtick重叠,python,matplotlib,Python,Matplotlib,我试图修改绘图的x记号,但matplotlib自动生成的记号标签之一并没有消失,我指定的记号标签与之重叠。代码是: ax[0].plot((zspace+1.),dndt_vs_z_9, color='blue', label=r'$M_s = 10^9$') ax[0].plot((zspace+1.),dndt_vs_z_10, color='red', label=r'$M_s = 10^{10}$') ax[0].plot((zspace[zspace<=2]+1.),dndt_v

我试图修改绘图的x记号,但matplotlib自动生成的记号标签之一并没有消失,我指定的记号标签与之重叠。代码是:

ax[0].plot((zspace+1.),dndt_vs_z_9, color='blue', label=r'$M_s = 10^9$')
ax[0].plot((zspace+1.),dndt_vs_z_10, color='red', label=r'$M_s = 10^{10}$')
ax[0].plot((zspace[zspace<=2]+1.),dndt_vs_z_11[zspace<=2], color='green', label=r'$M_s = 10^{11}$')
ax[0].plot((zspace[zspace<=2]+1.),(1./2.)*dndt_vs_z_11[zspace<=2], color='black')
ax[0].plot((zspace[zspace<=2]+1.),0.65*dndt_vs_z_11[zspace<=2], color='black')
ax[0].plot(gomez_11_x,gomez_11_y,color='blue', linestyle='dashed')
ax[0].plot(gomez_10_x,gomez_10_y,color='red', linestyle='dashed')
ax[0].plot(gomez_9_x,gomez_9_y,color='green', linestyle='dashed')
#ax[0].scatter(ill_shmr_z,ill_shmr_dndw_model_11)

ax[0].set_yscale('log')
ax[0].set_xscale('log')

ax[0].set_xticks([1,2,3,4,5], minor=True)
ax[0].set_xticklabels([1,2,3,4,5], minor=True, fontsize='20')
ax[0].set_xlim([1,5])
ax[0].set_ylim([1e-2,1e1])
ax[0].legend(loc='best', fontsize='20')

ax[0].grid(b = True, which='major')
ax[0].grid(b = True, which='minor', axis='x')
ax[0].set_xlabel(r'$1+z$', fontsize='15')
ax[0].set_ylabel(r'$\frac{dN}{dt}$', fontsize='20')
ax[0]。绘图((zspace+1.),dndt_vs_z_9,color='blue',label=r'$M_s=10^9$)
ax[0].绘图((zspace+1.),dndt_vs_z_10,color='red',label=r'$M_s=10^{10}$'))

ax[0]。绘图((zspace[zspace这里的问题来自使用对数刻度时混合主刻度和次刻度。在您的示例中,解决方案是使用A删除主刻度,只使用次刻度:

一个小例子是:

import matplotlib.pyplot as plt
import matplotlib.ticker

fig, (ax1, ax2) = plt.subplots(1,2, figsize=(12,7))

ax1.loglog([1,2,3,4,5])
ax1.set_xticks([1,2,3,4,5],minor=True)
ax1.set_xticklabels([1,2,3,4,5], minor=True, fontsize='20')
ax1.set_title("Reproduce problem")

ax2.loglog([1,2,3,4,5])
ax2.set_xticks([1,2,3,4,5],minor=True)
ax2.set_xticklabels([1,2,3,4,5], minor=True, fontsize='20')
ax2.xaxis.set_major_locator(matplotlib.ticker.NullLocator())
ax2.set_title("Apply fix")

plt.show()