季节性剥离图共享x轴

问题描述 投票:0回答:1

我正在研究一个海洋带状图,我想绘制4个共享x轴的图形。我希望它们像另一个链接一样,位于另一个之上,但是这样做不正确...

这是我的代码:

fig = plt.figure(figsize=(7, 9))

ax4 = plt.subplot(414)
sns.stripplot(x=clas, y=Tdust_ul, color='gold', edgecolor='k', label='_nolegend_')
ax4.set_ylim(20,42)
ax4.set_yticks([20,25,30,35,40],
           ['20','25','30','35','40'])
ax4.set_ylabel(r"T$_{dust}$ [K]")
xi = [0,1,2,3]
yi = [np.median(Tdust_ul[mask_class1]),np.median(Tdust_ul[mask_class2]),\
      np.median(Tdust_ul[mask_class3]),np.median(Tdust_ul[mask_class4])]
ax4.plot(xi, yi, color='green', alpha=0.7, zorder=0, label='_nolegend_')
ax4.scatter(xi,yi,s=50, marker="s", color='k', linewidth='0.75',label='_nolegend_')

ax4.set_xlabel("Merging class")
ax4.set_xticks([0,1,2,3]) 
ax4.set_xticklabels(["class 1","class 2","class 3","class 4"])
ax4.grid(True,axis='y',ls=":",c='gray',alpha=0.4)  

ax1 = plt.subplot(411, sharex = ax4)
ax1 = sns.stripplot(x=clas, y=dustm_ul, color='gold', edgecolor='k', label='_nolegend_')
ax1.set_ylim(1e6,6e8)
ax1.set_yscale('log')
ax1.set_ylabel(r"M$_{dust}$ [M$_{\odot}$]")
ax1.grid(True,axis='y',ls=":",c='gray',alpha=0.4)  
xi = [0,1,2,3]
yi = [np.median(dustm_ul[mask_class1]),np.median(dustm_ul[mask_class2]),\
      np.median(dustm_ul[mask_class3]),np.median(dustm_ul[mask_class4])]
ax1.plot(xi, yi, color='green', alpha=0.7, zorder=0, label='_nolegend_')
ax1.scatter(xi,yi,s=50, marker="s", color='k', linewidth='0.75',label='_nolegend_')

ax2 = plt.subplot(412, sharex = ax4)
sns.stripplot(x=clas, y=mstar_ul, color='gold', edgecolor='k', label='_nolegend_')
ax2.set_ylim(9e9,1e12)
ax2.set_yscale('log')
ax2.set_ylabel(r"M$_{star}$ [M$_{\odot}$]")
ax2.grid(True,axis='y',ls=":",c='gray',alpha=0.4)  
xi = [0,1,2,3]
yi = [np.median(mstar_ul[mask_class1]),np.median(mstar_ul[mask_class2]),\
      np.median(mstar_ul[mask_class3]),np.median(mstar_ul[mask_class4])]
ax2.plot(xi, yi, color='green', alpha=0.7, zorder=0, label='_nolegend_')
ax2.scatter(xi,yi,s=50, marker="s", color='k', linewidth='0.75',label='_nolegend_')

ax3 = plt.subplot(413, sharex = ax4)
sns.stripplot(x=clas, y=ssfr_ul, color='gold', edgecolor='k', label='_nolegend_')
ax3.set_ylim(1e-11,1e-8)
ax3.set_yscale('log')
ax3.set_ylabel(r"sSFR [yr$^{-1}$]")
ax3.grid(True,axis='y',ls=":",c='gray',alpha=0.4)  
xi = [0,1,2,3]
yi = [np.median(ssfr_ul[mask_class1]),np.median(ssfr_ul[mask_class2]),\
      np.median(ssfr_ul[mask_class3]),np.median(ssfr_ul[mask_class4])]
ax3.plot(xi, yi, color='green', alpha=0.7, zorder=0, label='_nolegend_')
ax3.scatter(xi,yi,s=50, marker="s", color='k', linewidth='0.75',label='_nolegend_')

plt.tight_layout()
plt.savefig('properties_per_class_strip.pdf', dpi=600)
plt.show()

我明白了:I get this

但是我想要与此类似的东西:desired plot

有人可以帮我吗?

提前感谢!

python seaborn
1个回答
0
投票
fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, sharex=True, gridspec_kw={'hspace':0})

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.