Python first x-y-ticks overlapping
Question: I am working on this problem for over an hour now, but all i tried failed so
far. In my plot the first values on x and y axes keep overlapping. I am using
tight layout to fix this problem, but it does not help. Also my z-ticks are
overlapping with the Z-axis. Thanks for any suggestions [![My
plot](http://i.stack.imgur.com/FK7CF.png)](http://i.stack.imgur.com/FK7CF.png)

    
    
    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)
    


Answer: Here I offer three method, maybe it would help.

### A. Enhance the figure size

_Before_

    
    
    fig = plt.figure()
    ax1 = plt.subplot(121,projection='3d')
    ax2 = plt.subplot(122)
    

[![enter image description
here](http://i.stack.imgur.com/BcI6T.png)](http://i.stack.imgur.com/BcI6T.png)

_Set the`figsize`_

    
    
    fig = plt.figure(figsize=(16,3))
    ax1 = plt.subplot(121,projection='3d')
    ax2 = plt.subplot(122)
    

[![enter image description
here](http://i.stack.imgur.com/wDI06.png)](http://i.stack.imgur.com/wDI06.png)

### B. Adjust the figure size of ax1.subplot

Change the portion of ax1.subplot by using **`gridspec`**.

    
    
    import mpl_toolkits.mplot3d.axes3d as axes3d
    import matplotlib.gridspec as gridspec
    fig = plt.figure(figsize = (12,6))
    gs = gridspec.GridSpec(1, 2,
                           width_ratios=[6,1],
                           height_ratios=[1,1]
                           )
    ax1 = plt.subplot(gs[0],projection='3d')
    ax2 = plt.subplot(gs[1])  
    

[![enter image description
here](http://i.stack.imgur.com/jdxbI.png)](http://i.stack.imgur.com/jdxbI.png)

### C. Adjust the frequency of x/y ticklabel.

The code below can adjust the xtick frequency. With less xticks and its
labels, the overlapping may be disappear.

    
    
    ax.set_xticks(np.arange(0,1,1,0.1))
    for xtick in ax.xaxis.get_ticklines()[1::2]: ### Hiding ticks each 2 steps.
        xtick.set_visible(False)     
    ax.set_xticklabels(np.arange(0,1,1,0.2),fontsize = 14)
    

