I am attempting to plot three graphs (histogram, heatmap, and heatmap) on a single row using seaborn
. I was able to produce all three graphs with the desired formatting, however, the x-axes of the three graphs are not aligned, which is shown below. I have also included the code I used to generate the figure.
It appears this is an effect of using the square=True
option for the heatmaps which results in them not using the full plotting space. How do I change the plotting (subplot) size of the histogram so that the all three x-axes are aligned? Is there a way to change the size of one of the subplots? If I have to define the size of each subplot is there a way to determine the size required to have all x-axes aligned?
style = dict(size=14, color='black')
fig, ax = plt.subplots(figsize=(12,4), ncols=3, nrows=1)
left = 0.125 # the left side of the subplots of the figure
right = 0.9 # the right side of the subplots of the figure
bottom = 0.1 # the bottom of the subplots of the figure
top = 1 # the top of the subplots of the figure
wspace = 1 # the amount of width reserved for blank space between subplots
hspace = 0 # the amount of height reserved for white space between subplots
# This function actually adjusts the sub plots using the above paramters
plt.subplots_adjust(
left = left,
bottom = bottom,
right = right,
top = top,
wspace = wspace,
hspace = hspace
)
boots = np.random.exponential(size=100000)
colors = sns.color_palette("colorblind")
ax[0] = sns.distplot(boots, kde=False, bins=20, ax=ax[0])
ax[0].axvline(x=0.8673, color=colors[1], linestyle = '--')
ax[0].axvline(x=.22, color="black", linestyle = "--")
ax[0].tick_params(labelsize = "13")
ax[0].set_xlabel("Average accuracy",fontsize=13)
ax[0].set_ylabel("Permutations", fontsize=13)
ax[1] = sns.heatmap(cf_matrices['CYANO-MLP'], vmin=0, vmax=1, cmap="Blues", square=True,
linewidths=0.1, linecolor = "grey", ax=ax[1],
cbar_kws={
'label': 'Mean Proportion\nClade Assignment',
'use_gridspec': False, 'location': "top",
"shrink": 1.2})
ax[1].tick_params(labelsize=13)
ax[1].text(8.2, 0.7, "N=11", **style)
ax[1].text(8.2, 1.7, "N=27", **style)
ax[1].text(8.2, 2.7, "N=30", **style)
ax[1].text(8.2, 3.7, "N=29", **style)
ax[1].text(8.2, 4.7, "N=3", **style)
ax[1].text(8.2, 5.7, "N=5", **style)
ax[1].text(8.2, 6.7, "N=4", **style)
ax[1].text(8.2, 7.7, "N=4", **style)
ax[1].figure.axes[-1].xaxis.label.set_size(13)
plt.setp(ax[1].get_xticklabels(), rotation=60)
ax[1].set_xlabel("Predicted Clade", size=15)
ax[1].set_ylabel("True Clade", size=15)
ax[2] = sns.heatmap(cf_matrices['CYANO-MLP-BAL'], vmin=0, vmax=1, cmap="Blues", square=True,
linewidths=0.1, linecolor = "grey", ax=ax[2],
cbar_kws={
'label': 'Mean Proportion\nClade Assignment',
'use_gridspec': False, 'location': "top",
"shrink": 1.2})
ax[2].tick_params(labelsize=13)
ax[2].text(8.2, 0.7, "N=30", **style)
ax[2].text(8.2, 1.7, "N=30", **style)
ax[2].text(8.2, 2.7, "N=30", **style)
ax[2].text(8.2, 3.7, "N=30", **style)
ax[2].text(8.2, 4.7, "N=30", **style)
ax[2].text(8.2, 5.7, "N=30", **style)
ax[2].text(8.2, 6.7, "N=30", **style)
ax[2].text(8.2, 7.7, "N=30", **style)
ax[2].figure.axes[-1].xaxis.label.set_size(13)
plt.setp(ax[2].get_xticklabels(), rotation=60)
ax[2].set_xlabel("Predicted Clade", size=15)
ax[2].set_ylabel("True Clade", size=15)
sns.despine(ax=ax[0])