【问题标题】:Seaborn displot - plot multiple plots in a a single figure [duplicate]Seaborn distplot - 在一个图中绘制多个图[重复]
【发布时间】:2021-04-06 00:01:14
【问题描述】:

这是我的数据框:

       age    income  memberdays
0       55  112000.0        1263
1       75  100000.0        1330
2       68   70000.0         978
3       65   53000.0        1054
4       58   51000.0        1144
   ...       ...         ...
14820   45   54000.0         939
14821   61   72000.0         900
14822   49   73000.0        1433
14823   83   50000.0        1758
14824   62   82000.0        1256

我想像这样在一个图中创建 3 个图:

fig, ax =plt.subplots(1,3)
sns.countplot(profile["age"], ax=ax[0])
sns.countplot(profile["income"], ax=ax[1])
sns.countplot(profile["memberdays"], ax=ax[2])
fig.show()

这可行,但我想使用 displot 函数分布图。

fig, ax =plt.subplots(1,3)
sns.displot(profile["age"], ax=ax[0])
sns.displot(profile["income"], ax=ax[1])
sns.displot(profile["memberdays"], ax=ax[2])
fig.show()

这将导致一个空的网格和三个独立的图。这是预期的行为吗?如果是,为什么会发生这种情况,我该如何克服?

Seaborn:0.11.0

【问题讨论】:

  • displot 是数字级别函数,不接受 ax= 参数。相反,您可以使用轴级函数,例如 kdeplothistplot。见official overview page

标签: python matplotlib seaborn


【解决方案1】:

Displot 不接受ax= 参数,请尝试改用histplot,如下所示:

fig, ax =plt.subplots(1,3,figsize=(20,10))
sns.histplot(profile["age"], ax=ax[0])
sns.histplot(profile["income"], ax=ax[1])
sns.histplot(profile["memberdays"], ax=ax[2])
fig.show()

它给出以下输出:

【讨论】:

    猜你喜欢
    • 2020-09-26
    • 1970-01-01
    • 2021-02-26
    • 1970-01-01
    • 2016-10-31
    • 2017-11-17
    • 2020-04-28
    • 2020-04-25
    • 2021-11-03
    相关资源
    最近更新 更多