首页 > 解决方案 > 在指定数量的行和列中绘制子图的问题

问题描述

所以我试图使用行和列中的子图来绘制“freq_cols”数据集中的所有列。但是,这些图仅显示所有框中的最后一列,而不是数据集中的各个列。这是我到目前为止所拥有的。请指教。谢谢!

freq_cols = frequency[['LF','LF_PCT','LF_NU','VLF','VLF_PCT','HF','HF_PCT','HF_NU','HF_LF','TP']]
fig, axs = plt.subplots(ncols = 5, nrows = 2, figsize = (30, 7))
for col_name, col_name in enumerate(freq_cols.columns):
    for i in range(2):
        for j in range(5):
            sns.distplot(freq_cols[col_name], color='green', kde=True, ax = axs[i, j])

单击此链接以查看所需绘图(顶行)与我得到的(底行)的屏幕截图

标签: subplotenumerate

解决方案


只是猜测问题。

你已经写了两次 col_name

for col_name, col_name in enumerate(freq_cols.columns):

可能是你想写

for col_num, col_name in enumerate(freq_cols.columns):

也许下面可能有用

freq_cols = frequency[['LF','LF_PCT','LF_NU','VLF','VLF_PCT','HF','HF_PCT','HF_NU','HF_LF','TP']]
fig, axs = plt.subplots(ncols = 5, nrows = 2, figsize = (30, 7))
for col_num, col_name in enumerate(freq_cols.columns):
    for i in range(2):
        for j in range(5):
            sns.distplot(freq_cols[col_name], color='green', kde=True, ax = axs[i, j])

推荐阅读