【发布时间】:2017-02-25 11:24:42
【问题描述】:
我目前有 2 个使用 seaborn 的子图:
import matplotlib.pyplot as plt
import seaborn.apionly as sns
f, (ax1, ax2) = plt.subplots(2, sharex=True)
sns.distplot(df['Difference'].values, ax=ax1) #array, top subplot
sns.boxplot(df['Difference'].values, ax=ax2, width=.4) #bottom subplot
sns.stripplot([cimin, cimax], color='r', marker='d') #overlay confidence intervals over boxplot
ax1.set_ylabel('Relative Frequency') #label only the top subplot
plt.xlabel('Difference')
plt.show()
这是输出:
我很困惑如何使 ax2(底部图)相对于 ax1(顶部图)变得更短。我正在查看 GridSpec (http://matplotlib.org/users/gridspec.html) 文档,但我不知道如何将其应用于 seaborn 对象。
问题:
- 如何使底部子图比顶部短 子情节?
- 顺便说一句,我如何将情节的标题“差异分布”移动到顶部上方 子情节?
感谢您的宝贵时间。
【问题讨论】:
-
为什么 seaborn 会导致 gridspec 出现问题?您还将从 gridspec 或 subplot2grid 获得轴对象。关于你的第二个问题:你试过
ax1.xaxis.set_label_position("top")吗? -
感谢您的建议!我最终使用了 fig.suptitle('bold figure suptitle', fontsize=14, fontweight='bold')
标签: python matplotlib seaborn subplot