我目前有 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对象。
问题:
- 与顶部相比,如何使底部子图更短
次要情节?
- 顺便说一句,如何将情节标题“差异分布”移动到顶部上方
次要情节?
感谢您的时间。
正如@dnalow 提到的,seaborn
没有影响GridSpec
,当您传递对Axes
函数的对象。就像这样:
import matplotlib.pyplot as plt
import seaborn.apionly as sns
import matplotlib.gridspec as gridspec
tips = sns.load_dataset("tips")
gridkw = dict(height_ratios=[5, 1])
fig, (ax1, ax2) = plt.subplots(2, 1, gridspec_kw=gridkw)
sns.distplot(tips.loc[:,'total_bill'], ax=ax1) #array, top subplot
sns.boxplot(tips.loc[:,'total_bill'], ax=ax2, width=.4) #bottom subplot
plt.show()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)