Skip to content Skip to sidebar Skip to footer

How To Adjust Height Of Individual Sublots In Seaborn Heatmap

I have a heatmap using seaborn and am trying to adjust the height of the 4th plot below. You will see that it only has 2 rows of data vs the others that have more: I have used the

Solution 1:

As normal, it is pretty funky/tedious with matplotlib. But here it is!

f = plt.figure(constrained_layout = True)  
specs = f.add_gridspec(ncols = 1, nrows = 4, height_ratios = [1,1,1,.5])

for spec, df in zip(specs, (df, df2, df3, df4)):
  ax = sns.heatmap(df,cbar=False,cmap=cmap, ax=f.add_subplot(spec)) 

You can change the heights relative to each other using the height_ratios. You could also implement a wdith_ratios parameter if you desired to change the relative widths. You could also implement a for loop to iterate over the graphing.


Post a Comment for "How To Adjust Height Of Individual Sublots In Seaborn Heatmap"