【问题标题】:Messy and overlapping plot when use pyplot.subplot and seaborns使用 pyplot.subplot 和 seaborns 时的混乱和重叠的情节
【发布时间】:2021-03-29 09:23:17
【问题描述】:

我尝试使用 seaborn 可视化异常值

columns =list(df_main.select_dtypes(['int64', 'float64']).columns)

for i, column in enumerate(columns):
  plt.subplot(19,1,1+i)
  sns.boxplot(x=df_main[column], orient="h")

plt.tight_layout()
plt.show()

这是我得到的结果:

有什么建议让它可读吗?我对任何可视化异常值的技术持开放态度。提前致谢

编辑: 我想要的输出可能如下所示:

【问题讨论】:

    标签: python matplotlib seaborn data-visualization outliers


    【解决方案1】:

    您融化了您的数据框并在 seaborn 中使用了分面图,例如使用 sns.catplot。示例数据集:

    df_main = pd.DataFrame([np.random.normal(i,1,100) for i in range(19)]).T
    

    运行您的代码,如下所示:

    使用 sns.catplot:

    sns.catplot(row="variable",x="value",
    data=df_main.melt(),kind="box",height=0.8,aspect=7)
    

    【讨论】:

      【解决方案2】:

      您可以试试这段代码并告诉我您的问题是否解决了吗?这是我用于绘图的一般结构。

      columns =list(df_main.select_dtypes(['int64', 'float64']).columns)
      
      grid = plt.GridSpec(19, 1)
      figure = plt.figure()
      
      for i, column in enumerate(columns):
        ax = figure.add_subplot(grid[i])
        sns.boxplot(x=df_main[column], orient="h", ax=ax)
      
      plt.tight_layout()
      plt.show()
      
      

      【讨论】:

      • 输出仍然很乱,先生
      • 我已经用替代方法编辑了我的答案。我认为没有必要做出新的答案。如果你能用这个试一试就好了。否则我不得不承认我帮不上忙。我需要数据来重现您的问题。对不起
      猜你喜欢
      • 2011-01-25
      • 1970-01-01
      • 2015-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多