I want to show 2 boxplots on 3 axes. First problem I solved with gently help here.
The first boxplot is plotted with an interrupted x-axes.
Now I want to plot a second boxplot on a 3rd axis. The x-axis should start where the x-axis of ax2 ended.
I tried it with twiny(), but that produced not what I want.
f, (ax1, ax2, ax3) = plt.subplots(ncols=3, sharey=True, gridspec_kw={'width_ratios':[1,5,3]}, figsize=(10,2))
sns.boxplot(data=df,
x = df.loc[:,'days_before'],
y= df.loc[:,'T1'],
hue='T1',
ax=ax1, showfliers = True)
sns.boxplot(data=df,
x = df.loc[:,'days_before'],
y= df.loc[:,'T1'],
hue='T1',
ax=ax2)
sns.boxplot(data=df,
x = df.loc[:,'days_after'],
y= df.loc[:,'T1'],
hue='T1',
ax=ax3, showfliers = True)
ax1.set_xlabel(
'')
ax1.set_ylabel('')
ax2.set_xlabel('days before')
ax3.set_ylabel('')
ax1.legend().remove()
ax2.legend().remove()
ax3.legend().remove()
ax1.spines['right'].set_visible(False)
ax2.spines['left'].set_visible(False)
ax2.spines['right'].set_visible(False)
ax2.yaxis.set_visible(False)
ax3.yaxis.set_visible(False)
ax3.spines['left'].set_visible(False)
ax1.set_xlim(right=-1750)
ax2.set_xlim(left=-700)
ax3=ax2.twiny()
Is it possible to close the gap between the 2nd and 3rd axis?
Found a solution:
f, (ax1, ax2) = plt.subplots(ncols=2, sharey=True, gridspec_kw={'width_ratios':[1,5]}, figsize=(10,2))
sns.boxplot(data=df,
x = df.loc[:,'days_before'],
y= df.loc[:,'T1'],
hue='T1',
ax=ax1, showfliers = True)
sns.boxplot(data=df,
x = df.loc[:,'days_before'],
y= df.loc[:,'T1'],
hue='T1',
ax=ax2)
sns.boxplot(data=df,
x = df.loc[:,'days_after'],
y= df.loc[:,'T1'],
hue='T1',
ax=ax2, showfliers = True)
ax1.set_xlabel('')
ax1.set_ylabel('')
ax2.set_xlabel('days before')
ax1.legend().remove()
ax2.legend().remove()
ax1.spines['right'].set_visible(False)
ax2.spines['left'].set_visible(False)
ax2.yaxis.set_visible(False)
ax1.set_xlim(right=-1750)
ax2.set_xlim(left=-700)
plt.savefig("example_3 plots.jpg")
plt.show()