相关疑难解决方法(0)

seaborn 未在定义的子图中绘制

我正在尝试使用此代码并排绘制两个分布图

fig,(ax1,ax2) = plt.subplots(1,2)

sns.displot(x =X_train['Age'], hue=y_train, ax=ax1)
sns.displot(x =X_train['Fare'], hue=y_train, ax=ax2)
Run Code Online (Sandbox Code Playgroud)

它返回以下结果(两个空的子图,后跟一个分布在两行上的图)-

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

如果我用 violinplot 尝试相同的代码,它会按预期返回结果

fig,(ax1,ax2) = plt.subplots(1,2)

sns.violinplot(y_train, X_train['Age'], ax=ax1)
sns.violinplot(y_train, X_train['Fare'], ax=ax2)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

为什么 displot 返回不同类型的输出,我该怎么做才能在同一行上输出两个图?

python data-visualization seaborn

10
推荐指数
1
解决办法
5567
查看次数

将线图添加到 Facetgrid 图中

RelPlot使用 Seaborn 绘制了一个简单的图,它返回了一个Facetgrid对象。我使用的代码如下:

import seaborn as sns

palette = sns.color_palette("rocket_r")

g1 = sns.relplot(
    data=df,
    x="number_of_weeks", y="avg_streams",
    hue="state", col="state",
    kind="line", palette=palette,
    height=5, aspect=1, facet_kws=dict(sharex=False), col_wrap=3, 
)
Run Code Online (Sandbox Code Playgroud)

显示了以下情节: 阴谋

我正在使用的数据框具有以下结构:

   avg_streams  date    year number_of_weeks state
4   0.104011    31-01   2020    4   it
5   1.211951    07-02   2020    5   it
6   0.559374    14-02   2020    6   it
7   0.304257    21-02   2020    7   it
8   0.199218    28-02   2020    8   it
... ... ... ... ... ...
175 -0.938890   26-06   2020    25  br
176 -0.483821 …
Run Code Online (Sandbox Code Playgroud)

python matplotlib subplot line-plot seaborn

2
推荐指数
1
解决办法
3037
查看次数