简体   繁体   中英

seaborn stripplot share x-axis

I am working on a seaborn stripplot and I want to plot 4 graphs sharing the x-axis. I want them to be one on-top of the other, like in the photo of the second link, but it does not properly...

This is my code:

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: 我明白了

But I want something similar to this one: 想要的情节

Could anybody please help me?

Thanks in advance!

fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, sharex=True, gridspec_kw={'hspace':0})

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM