Python Matplotlib子图2带轴标签的网格填充

Python Matplotlib子图2带轴标签的网格填充,python,matplotlib,plot,axis-labels,subplot,Python,Matplotlib,Plot,Axis Labels,Subplot,非常感谢您为使subplot2grid和Axis标签能够很好地协同工作所提供的任何帮助。如图所示,一些轴标签与相邻子批次的表面重叠。 附加了一些代码,以防有帮助 def init_plot(self): self.f0 = plt.figure(num = 0, figsize = (12, 8))#, dpi = 100) self.f0.suptitle("CFM diffusion", fontsize=12) self.ax01 = plt.subplot2gr

非常感谢您为使subplot2grid和Axis标签能够很好地协同工作所提供的任何帮助。如图所示,一些轴标签与相邻子批次的表面重叠。
附加了一些代码,以防有帮助

def init_plot(self):

    self.f0 = plt.figure(num = 0, figsize = (12, 8))#, dpi = 100)
    self.f0.suptitle("CFM diffusion", fontsize=12)
    self.ax01 = plt.subplot2grid((2, 3), (0, 0))
    self.ax02 = plt.subplot2grid((2, 3), (0, 1))
    self.ax03 = plt.subplot2grid((2, 3), (1, 0))
    self.ax04 = plt.subplot2grid((2, 3), (1, 1))
    self.ax05 = plt.subplot2grid((2, 3), (0, 2))
    self.ax06 = plt.subplot2grid((2, 3), (1, 2))


    self.ax01.set_ylim((300, 0))
    self.ax02.set_ylim((300,0))
    self.ax03.set_ylim((230, 250))
    self.ax04.set_ylim((0.08, 0.22))
    self.ax02.set_xlim((230, 250))
    self.ax03.set_xlim((self.model_time[0], self.model_time[-1]))
    self.ax04.set_xlim((self.model_time[0], self.model_time[-1]))
    self.ax05.set_ylim((300,0))
    self.ax05.set_xlim((0, 0.125))
    self.ax06.set_xlim((self.model_time[0], self.model_time[-1]))
    self.ax06.set_ylim((0.08, 0.125))

    self.ax01.set_ylabel(r"Depth [m]")
    self.ax01.set_xlabel(r"Density [$\mathrm{kgm}^{-3}$]")
    self.ax02.set_ylabel(r"Depth [m]")
    self.ax02.set_xlabel(r"Temperature [K]")
    self.ax03.set_ylabel(r"Temperature Forcing [K]")
    self.ax03.set_xlabel(r"Model Time [y]")
    self.ax04.set_ylabel(r"Accumulation Forcing [$\mathrm{my}^{-1}$ ice eq.]")
    self.ax04.set_xlabel(r"Model Time [y]")
    self.ax05.set_ylabel(r"Depth [m]")
    self.ax05.set_xlabel(r"Diffusion Length [m]")
    self.ax06.set_ylabel(r"$\sigma'_{18}$ [m]")
    self.ax06.set_xlabel(r"Model Time [y]")

    # self.ax01.set_title('Density profile')
    # self.ax02.set_title('Temp. profile')
    # self.ax03.set_title('Temperature Forcing')
    # self.ax04.set_title('Accum Forcing')
    # self.ax05.set_title('Diffusion Length')
    # self.ax06.set_title('Diffusion Length at CO')

    self.hlp011 = self.ax01.plot(self.rho_hl*1000, self.z_hl, "r--")
    self.p011, = self.ax01.plot(self.rho[0][1:], self.z[0][1:],'b-')
    self.p012, = self.ax02.plot(self.temperature[0][1:], self.z[0][1:], 'k-')
    self.p021, = self.ax03.plot(self.climate[0,0], self.climate[0,2],'k-')
    self.p022, = self.ax04.plot(self.climate[0,0], self.climate[0,1], 'k-')
    print(self.climate[0,1])
    self.p023, = self.ax05.plot(self.iso_sigmaD[0][1:], self.z[0][1:], 'r-')
    self.p024, = self.ax05.plot(self.iso_sigma18[0][1:], self.z[0][1:], 'b-')
    self.iso_sigma18_co = np.array((self.iso_sigma18[0][1:][self.rho[0][1:]>804.3][0],))
    self.p025, = self.ax06.plot(self.climate[0,0], self.iso_sigma18_co[0], 'b-')

    return
最好的 Vas

请尝试使用指南

在代码中,只需在创建
self.f0
后添加这一行:

self.f0.tight_layout()
最后的答案是: self.f0.tight_layout()处理一些事情,并在顶部添加一些填充来说明标题

class CfmPlotter():

def __init__(self, fpath = None):


    hl_inst = herron_lang.HL(temp = -40.0+273.15, accu= 0.0917, rho_o=350.)

    self.z_hl, self.rho_hl = hl_inst(np.arange(0,400, 0.01))
    # fpath = "./DO_results/DO_tests_vary_tr_time/cfm_DO_trtime_1500/Goujon_DO_trtime_1500.hdf5"
    self.fpath = fpath
    f = h5py.File(fpath)
    self.fs = os.path.split(fpath)[1]
    print f.keys()
    self.z = f["depth"][:]
    self.rho = f["density"][:]
    self.temperature = f["temperature"][:]
    self.age = f["age"][:]
    self.climate = f["Modelclimate"][:]
    self.iso_sigmaD = f["iso_sigmaD"][:]
    self.iso_sigma18 = f["iso_sigma18"][:]
    self.iso_sigma17 = f["iso_sigma17"][:]
    self.model_time = np.array(([a[0] for a in self.z[:]]))

    f.close()
    return


def init_plot(self):

    self.f0 = plt.figure(num = 0, figsize = (10, 6))#, dpi = 100)
    self.f0.tight_layout(pad = 2.8)
    self.f0.suptitle("CFM diffusion", fontsize=12)
    self.ax01 = plt.subplot2grid((2, 3), (0, 0))
    self.ax02 = plt.subplot2grid((2, 3), (0, 1))
    self.ax03 = plt.subplot2grid((2, 3), (1, 0))
    self.ax04 = plt.subplot2grid((2, 3), (1, 1))
    self.ax05 = plt.subplot2grid((2, 3), (0, 2))
    self.ax06 = plt.subplot2grid((2, 3), (1, 2))


    self.ax01.set_ylim((300, 0))
    self.ax02.set_ylim((300,0))
    self.ax03.set_ylim((230, 250))
    self.ax04.set_ylim((0.08, 0.22))
    self.ax02.set_xlim((230, 250))
    self.ax03.set_xlim((self.model_time[0], self.model_time[-1]))
    self.ax04.set_xlim((self.model_time[0], self.model_time[-1]))
    self.ax05.set_ylim((300,0))
    self.ax05.set_xlim((0, 0.125))
    self.ax06.set_xlim((self.model_time[0], self.model_time[-1]))
    self.ax06.set_ylim((0.08, 0.125))

    self.ax01.set_ylabel(r"Depth [m]")
    self.ax01.set_xlabel(r"Density [$\mathrm{kgm}^{-3}$]")
    self.ax02.set_ylabel(r"Depth [m]")
    self.ax02.set_xlabel(r"Temperature [K]")
    self.ax03.set_ylabel(r"Temperature Forcing [K]")
    self.ax03.set_xlabel(r"Model Time [y]")
    self.ax04.set_ylabel(r"Accumulation Forcing [$\mathrm{my}^{-1}$ ice eq.]")
    self.ax04.set_xlabel(r"Model Time [y]")
    self.ax05.set_ylabel(r"Depth [m]")
    self.ax05.set_xlabel(r"Diffusion Length [m]")
    self.ax06.set_ylabel(r"$\sigma'_{18}$ [m]")
    self.ax06.set_xlabel(r"Model Time [y]")

    # self.ax01.set_title('Density profile')
    # self.ax02.set_title('Temp. profile')
    # self.ax03.set_title('Temperature Forcing')
    # self.ax04.set_title('Accum Forcing')
    # self.ax05.set_title('Diffusion Length')
    # self.ax06.set_title('Diffusion Length at CO')

    self.hlp011 = self.ax01.plot(self.rho_hl*1000, self.z_hl, "r--")
    self.p011, = self.ax01.plot(self.rho[0][1:], self.z[0][1:],'b-')
    self.p012, = self.ax02.plot(self.temperature[0][1:], self.z[0][1:], 'k-')
    self.p021, = self.ax03.plot(self.climate[0,0], self.climate[0,2],'k-')
    self.p022, = self.ax04.plot(self.climate[0,0], self.climate[0,1], 'k-')
    print(self.climate[0,1])
    self.p023, = self.ax05.plot(self.iso_sigmaD[0][1:], self.z[0][1:], 'r-')
    self.p024, = self.ax05.plot(self.iso_sigma18[0][1:], self.z[0][1:], 'b-')
    self.iso_sigma18_co = np.array((self.iso_sigma18[0][1:][self.rho[0][1:]>804.3][0],))
    self.p025, = self.ax06.plot(self.climate[0,0], self.iso_sigma18_co[0], 'b-')

    return