python xticks旋转后发生错位_Python第一个xyticks重叠

我正在研究这个问题一个多小时了,但迄今为止我所做的一切都失败了。

在我的绘图中,x轴和y轴上的第一个值保持重叠。我使用紧凑的布局来解决这个问题,但是没有帮助。

另外,我的z记号与z轴重叠。

谢谢你的建议

font = {'family' : 'normal',

'weight' : 'normal',

'size' : 18}

matplotlib.rc('font', **font)

time=round(t[time_period],0)

fig = plt.figure(figsize=(10,5))

###first subplot

ax = fig.add_subplot(1, 2, 1, projection='3d')

surf=ax.plot_surface(X_MESH, Y_MESH, Meshgrid_Output, rstride=1, cstride=1, cmap=cm.jet,linewidth=0, antialiased=False)

ax.set_xlabel(name+"$_"+str(most_sensitive[0])+" in "+str(unit)+"$")

ax.set_ylabel(name+"$_"+str(most_sensitive[1])+"$ in "+str(unit))

ax.set_zlabel("$\Delta$Output in [C]")

##formating labels

ax.xaxis._axinfo['label']['space_factor'] = 4.2

ax.yaxis._axinfo['label']['space_factor'] = 4.2

ax.zaxis._axinfo['label']['space_factor'] = 3

##position and rotation ticks

ax.xaxis._axinfo['tick']['inward_factor'] = 0

ax.xaxis._axinfo['tick']['outward_factor'] = 0.4

ax.yaxis._axinfo['tick']['inward_factor'] = 0

ax.yaxis._axinfo['tick']['outward_factor'] = 0.4

ax.zaxis._axinfo['tick']['inward_factor'] = 0

ax.zaxis._axinfo['tick']['outward_factor'] = 0.4

ax.zaxis._axinfo['tick']['outward_factor'] = 0.4

plt.xticks(rotation=45)

plt.yticks(rotation=325)

ax.grid(False)

## setting background

ax.xaxis.pane.set_edgecolor('black')

ax.yaxis.pane.set_edgecolor('black')

ax.xaxis.pane.fill = False

ax.yaxis.pane.fill = False

ax.zaxis.pane.fill = False

#set nubmer of ticks

ab, bc = ax.get_xlim( )

ax.set_xticks( np.linspace(ab, bc, 4 ) )

cd, de = ax.get_ylim( )

ax.set_yticks( np.linspace(cd, de, 4 ) )

lb, ub = ax.get_zlim( )

ax.set_zticks( np.linspace(lb, ub, 5 ) )

##round values

ax.xaxis.set_major_formatter(mtick.FormatStrFormatter('%.3f'))

ax.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.3f'))

ax.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.3f'))

##set point of view

angle=132

ax.view_init(30, angle)

##second subplot

ax = fig.add_subplot(1, 2, 2)

cax=ax.imshow(Meshgrid_Output, extent=[Y_MESH.min(),Y_MESH.max(),X_MESH.max(),X_MESH.min()],aspect='auto',interpolation='nearest',cmap=cm.jet)

ax.set_xlabel(name+"$_"+str(most_sensitive[0])+"$ in "+str(unit))

ax.set_ylabel(name+"$_"+str(most_sensitive[1])+"$ in "+str(unit))

#set nubmer of ticks

ab, bc = ax.get_xlim( )

ax.set_xticks( np.linspace(ab, bc, 4) )

cd, de = ax.get_ylim( )

ax.set_yticks( np.linspace(cd, de, 4 ) )

##round values

ax.xaxis.set_major_formatter(mtick.FormatStrFormatter('%.3f'))

ax.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.3f'))

ax.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.3f'))

#postion ticks

ax.yaxis.tick_right()

ax.xaxis.set_label_position('top')

ax.grid(True)

## formation colorbar

cbar=fig.colorbar(cax,orientation='horizontal',aspect=20,pad=0.08)

cbar.locator = ticker.MaxNLocator(nbins=6)

cbar.update_ticks()

#Posion both subplots

fig.subplots_adjust(bottom=0.2)

fig.subplots_adjust(wspace=0.3)

你可能感兴趣的:(python,xticks旋转后发生错位)