循环中的Seborn图 [英] Seaborn plots in a loop

查看:20
本文介绍了循环中的Seborn图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spyder并在循环中绘制Seborn CountPlot。问题是,情节似乎是在同一个物体上一个接一个地发生,而我最终只看到了情节的最后一个实例。如何在控制台中一个接一个地查看每个绘图?

for col in df.columns:
   if  ((df[col].dtype == np.float64) | (df[col].dtype == np.int64)):
       i=0
       #Later
   else :
       print(col +' count plot 
') 
       sns.countplot(x =col, data =df)
       sns.plt.title(col +' count plot')        

推荐答案

您可以在每个循环或可能在不同轴上绘制的情况下创建新图形。下面是创建每个循环的新图形的代码。它还可以更有效地获取int和Float列。

import matplotlib.pyplot as plt

df1 = df.select_dtypes([np.int, np.float])
for i, col in enumerate(df1.columns):
    plt.figure(i)
    sns.countplot(x=col, data=df1)

这篇关于循环中的Seborn图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆