seaborn 中的子图 [英] Subplots in seaborn

查看:74
本文介绍了seaborn 中的子图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用 2 个 seaborn 地块(子地块)创建一个地块

how do I create one plot with 2 seaborn plots (subplots)

如何将 2 个 seaborn 地块合并为 1 个?

How to merge 2 seaborn plots into 1?

plt.figure(figsize = (12, 6))
ax = sns.scatterplot(x = model1.fittedvalues, y = model1.resid)
plt.grid()
ax.axhline(y=0, color='r', linewidth=4) 
ax.set_xlabel("vysvětlovaná proměnná");
ax.set_ylabel("residua");


plt.figure(figsize = (12, 6))
ax = sns.distplot(a = model1.resid, bins = 40, norm_hist=True,)
plt.grid()
ax.set_title("Histogram reziduí", fontsize = 25);

推荐答案

您可以随心所欲地创建子图(使用 plt.subplots(), fig.add_subplot()GridSpec,你自己命名),然后使用 ax=

You can create your subplots anyway you like (using plt.subplots(), fig.add_subplot(), GridSpec, you name it), then pass a reference to the axes to the seaborn functions using ax=<your axes reference>

fig, (ax1, ax2) = plt.subplots(1,2, figsize = (24, 6))
sns.scatterplot(x = model1.fittedvalues, y = model1.resid, ax=ax1)
ax1.grid()
ax1.axhline(y=0, color='r', linewidth=4) 
ax1.set_xlabel("vysvětlovaná proměnná");
ax1.set_ylabel("residua");

sns.distplot(a = model1.resid, bins = 40, norm_hist=True, ax=ax2)
ax2.grid()
ax2.set_title("Histogram reziduí", fontsize = 25);

这篇关于seaborn 中的子图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆