Python subsections leave space for common axis labels

I have the following code that does four subheadings in one drawing:

f = figure( figsize=(7,7) ) f.add_axes([0.2,0.175,0.75,0.75]) f.subplots_adjust(left=0.15) f.clf() ax = f.add_subplot(111) ax1 = f.add_subplot(221) ax2 = f.add_subplot(222) ax3 = f.add_subplot(223) ax4 = f.add_subplot(224) ax.xaxis.set_major_formatter( NullFormatter() ) ax.yaxis.set_major_formatter( NullFormatter() ) ax2.xaxis.set_major_formatter( NullFormatter() ) ax2.yaxis.set_major_formatter( NullFormatter() ) ax1.xaxis.set_major_formatter( NullFormatter() ) ax4.yaxis.set_major_formatter( NullFormatter() ) f.subplots_adjust(wspace=0,hspace=0) ax1.plot(tbins[0:24], mean_yszth1, color='r', label='mean', marker='.', lw=3) ax2.plot(tbins[0:24], mean_ysz1, color='r', label='mean', marker='.', lw=3) ax3.plot(tbins[0:24], mean_yszth2, color='r', label='mean', marker='.', lw=3) ax4.plot(tbins[0:24], mean_ysz2, color='r', label='mean', marker='.', lw=3) ax1.set_xlim(0,12) ax1.set_ylim(-0.5,0.5) ax2.set_xlim(0,12) ax2.set_ylim(-0.5,0.5) ax3.set_xlim(0,12) ax3.set_ylim(-0.5,0.5) ax4.set_xlim(0,12) ax4.set_ylim(-0.5,0.5) ax.set_xlabel(r"$\mathrm{Time\ since\ last\ merger\ (Gyr)}$") ax.set_ylabel(r"$\mathrm{\Delta Y_{SZ}/Y_{SZ}}$") 

The result is as follows:

As you can see, the axis labels overlap with ticks. I would like to slightly move the labels of the main axes from the axes. I cannot figure out how best to do this.

+3
source share
1 answer

Use the labelpad parameter of the set_ylabel and set_xlabel :

 Definition: ax.set_ylabel(self, ylabel, fontdict=None, labelpad=None, **kwargs) Docstring: Call signature:: set_ylabel(ylabel, fontdict=None, labelpad=None, **kwargs) Set the label for the yaxis *labelpad* is the spacing in points between the label and the y-axis 

This is what I get with the shortcut set to 50 (x) and 60 (y). I had to manually resize the margins because the labels were outside the picture frame when using the default configuration.

enter image description here

Edit
From your comments, it seems that you can use a very old version of matplotlib. The Labelpad parameter was in matplotlib from many versions ago, but the method for installing it may be different (I do not know for sure).
On the Internet, I found a few comments that point to this usage:

 ax.xaxis.LABELPAD = 8 # default is 5 

I also saw this as:

 ax.xaxis.labelpad = 8 
+3
source

Source: https://habr.com/ru/post/1443674/


All Articles