0

I want to create a plot with multiple subplots involving heatmaps and barplots. I am facing problems with using shared X axis across the plots.

This is my code:

fig = plt.figure(figsize=(4, 4))
f,(ax0,ax1,ax2) = plt.subplots(3,1,sharex=True,figsize=[3,8],
                                                   gridspec_kw={'height_ratios':[1,0.25,1],'width_ratios':[1]})
ax0.get_shared_x_axes().join(ax1,ax2)

g0 = sns.barplot(data=tpm,color='blue',ax=ax0,lw=lw)
g1 = sns.heatmap(prep(sex),cmap=sex_clr,cbar=False,ax=ax1,linewidths=lw,linecolor='white')
g1.set(xlabel='',ylabel='')
g3 = sns.barplot(data=tmb_val,color='blue',ax=ax2,lw=lw)

This is my output:

enter image description here

Here I mentioned sharex=True and also used get_shared_axes() but nothing worked. Can anyone help me with this?

Yash
  • 275
  • 1
  • 8
  • Your question is hard to answer without reproducible test data. Could you provide some? How do the x-values look like? Are they consecutive numbers? Strings? .... – JohanC Jul 12 '23 at 16:55
  • 1
    [How to align yticklabels when combining a barplot with heatmap](https://stackoverflow.com/q/73241420/7758804) is applicable to the issue, and should resolve the issue with the heatmap cell being sliced, and not aligning. – Trenton McKinney Jul 12 '23 at 17:31

0 Answers0