我有四个使用matplotlib.gridspec
包的子图。但是,我无法在第二个子图(ax2
)上绘制标签,我想知道如何做到这一点。我的代码如下:
fig = plt.figure(figsize=(11,7))
gs1 = gridspec.GridSpec(3, 1)
gs1.update(left=0.02, right=0.45, hspace=.1)
ax1 = fig.add_subplot(gs1[0, 0])
ax2 = fig.add_subplot(gs1[1:,0])
gs2 = gridspec.GridSpec(3, 1)
gs2.update(left=0.55, right=0.98, hspace=.1)
ax3 = fig.add_subplot(gs2[0, 0])
ax4 = fig.add_subplot(gs2[1:,0])
ax1.plot(advwbarJFM.mean(dim=['eta_rho','xi_rho'])[:nz], advwbarJFM.z[:nz], 'b')
ax1.plot(advubarJFM.mean(dim=['eta_rho','xi_u'])[:nz], advubarJFM.z[:nz], 'b--')
ax1.plot(advvbarJFM.mean(dim=['eta_v','xi_rho'])[:nz], advvbarJFM.z[:nz], 'b-.')
ax1.plot(advwbarJAS.mean(dim=['eta_rho','xi_rho'])[:nz], advwbarJFM.z[:nz], 'r')
ax1.plot(advubarJAS.mean(dim=['eta_rho','xi_u'])[:nz], advubarJFM.z[:nz], 'r--')
ax1.plot(advvbarJAS.mean(dim=['eta_v','xi_rho'])[:nz], advvbarJFM.z[:nz], 'r-.')
ax1.set_xlim([-6e-6, 4e-6])
ax1.set_xticks([])
# ax1.set_title(r"Monthly variability")
ax2.plot(advwbarJFM.mean(dim=['eta_rho','xi_rho'])[nz:], advwbarJFM.z[nz:], 'b', label=r"$\overline{w} \overline{O_2}$")
ax2.plot(advubarJFM.mean(dim=['eta_rho','xi_u'])[nz:], advubarJFM.z[nz:], 'b--', label=r"$\overline{u} \overline{O_2}$")
ax2.plot(advvbarJFM.mean(dim=['eta_v','xi_rho'])[nz:], advvbarJFM.z[nz:], 'b-.', label=r"$\overline{v} \overline{O_2}$")
ax2.plot(advwbarJAS.mean(dim=['eta_rho','xi_rho'])[nz:], advwbarJFM.z[nz:], 'r', label=r"$\overline{w} \overline{O_2}$")
ax2.plot(advubarJAS.mean(dim=['eta_rho','xi_u'])[nz:], advubarJFM.z[nz:], 'r--', label=r"$\overline{u} \overline{O_2}$")
ax2.plot(advvbarJAS.mean(dim=['eta_v','xi_rho'])[nz:], advvbarJFM.z[nz:], 'r-.', label=r"$\overline{v} \overline{O_2}$")
ax2.set_xticks([-6e-6, -4e-6, -2e-6, 0, 2e-6, 4e-6])
ax3.plot(advwppJFM.mean(dim=['eta_rho','xi_rho'])[:nz], advwppJFM.z[:nz], 'b')
ax3.plot(advuppJFM.mean(dim=['eta_rho','xi_u'])[:nz], advuppJFM.z[:nz], 'b--')
ax3.plot(advvppJFM.mean(dim=['eta_v','xi_rho'])[:nz], advvppJFM.z[:nz], 'b-.')
ax3.plot(advwppJAS.mean(dim=['eta_rho','xi_rho'])[:nz], advwppJFM.z[:nz], 'r')
ax3.plot(advuppJAS.mean(dim=['eta_rho','xi_u'])[:nz], advuppJFM.z[:nz], 'r--')
ax3.plot(advvppJAS.mean(dim=['eta_v','xi_rho'])[:nz], advvppJFM.z[:nz], 'r-.')
ax3.set_xlim([-1.5e-6, 1e-6])
ax3.set_xticks([])
# ax3.set_title(r"Submonthly variability")
ax4.plot(advwppJFM.mean(dim=['eta_rho','xi_rho'])[nz:], advwppJFM.z[nz:], 'b', label=r"$\overline{w'' O_2''}$")
ax4.plot(advuppJFM.mean(dim=['eta_rho','xi_u'])[nz:], advuppJFM.z[nz:], 'b--', label=r"$\overline{u'' O_2''}$")
ax4.plot(advvppJFM.mean(dim=['eta_v','xi_rho'])[nz:], advvppJFM.z[nz:], 'b-.', label=r"$\overline{v'' O_2''}$")
ax4.plot(advwppJAS.mean(dim=['eta_rho','xi_rho'])[nz:], advwppJFM.z[nz:], 'r', label=r"$\overline{w'' O_2''}$")
ax4.plot(advuppJAS.mean(dim=['eta_rho','xi_u'])[nz:], advuppJFM.z[nz:], 'r--', label=r"$\overline{u'' O_2''}$")
ax4.plot(advvppJAS.mean(dim=['eta_v','xi_rho'])[nz:], advvppJFM.z[nz:], 'r-.', label=r"$\overline{v'' O_2''}$")
ax4.set_xticks([-1.5e-6, -1e-6, -5e-7, 0, 5e-7, 1e-6])
plt.suptitle(r"$O_2$ fluxes", y=.95, fontsize=15)
plt.legend(loc='lower left')
plt.show()
提前谢谢!