更改子图的大小,以便直方图和热图x轴阵容

时间:2019-02-12 17:17:43

标签: python matplotlib seaborn

我正在尝试使用seaborn在单个行上绘制三个图形(直方图,热图和热图)。我能够以所需的格式生成所有三个图,但是,三个图的x轴未对齐,如下所示。我还包括了用于生成图形的代码。

看来,这是对热图使用square=True选项的结果,导致它们未使用完整的绘图空间。如何更改直方图的绘图(子图)大小,以使所有三个X轴对齐?有没有办法改变其中一个子图的大小?如果我必须定义每个子图的大小,是否可以确定对齐所有X轴所需的大小?
 Example Figure

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])

0 个答案:

没有答案
相关问题