列值的seaborn镶嵌面网格

2024-10-02 10:29:10 发布

您现在位置:Python中文网/ 问答频道 /正文

有一只熊猫dataframe像下面这样

Date,Id_x,EC Id,ActDlS,pmAcUlPr
4/27/2020,1139,1139,1131,6
4/28/2020,1139,1139,1131,6
4/29/2020,1139,1139,1131,6
4/30/2020,1139,1139,1131,6
5/1/2020,1140,1140,1132,6

需要使用seaborn为下面的Date列创建所有列的图表。实际数据集中可能有100个这样的列

我试图使用Seaborn doc中的示例

import seaborn as sns; sns.set(style="ticks", color_codes=True)
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="time", row="smoker") 

需要帮助以sns.FacetGrid中可以接受的格式获取数据集

enter image description here


Tags: 数据id示例dataframedatedoc图表seaborn
1条回答
网友
1楼 · 发布于 2024-10-02 10:29:10

您不能在本例中使用FacetGrid:您没有在Date中为每个值绘制一个图形。相反,您需要使用plt.subplot

它将如下所示:

# defining number of rows and columns
ncols = 2
nrows = len(df) % ncols + 1


# creation of figure and axes
fig, axes = plt.subplots(
    nrows=nrows,
    ncols=ncols,
    sharey=True,
    figsize=(ncols*5, nrows*4)
)

# loop for plotting each column
for i, col in enumerate(df):
    sns.barplot(x=df.index, y=df[col],
                ax=axes[i % 2, i // 2], color='royalblue').set_title(col)

fig.tight_layout()

Result

相关问题 更多 >

    热门问题