Python 3.x 使用seaborn绘制多个直方图
我有一个36列的数据框。我想用seaborn一次性(6x6)绘制每个特征的直方图。基本上是复制df.hist(),但使用seaborn。我下面的代码只显示了第一个功能的绘图,其他所有功能都为空 测试数据帧:Python 3.x 使用seaborn绘制多个直方图,python-3.x,pandas,plot,histogram,seaborn,Python 3.x,Pandas,Plot,Histogram,Seaborn,我有一个36列的数据框。我想用seaborn一次性(6x6)绘制每个特征的直方图。基本上是复制df.hist(),但使用seaborn。我下面的代码只显示了第一个功能的绘图,其他所有功能都为空 测试数据帧: df = pd.DataFrame(np.random.randint(0,100,size=(100, 36)), columns=range(0,36)) 我的代码: import seaborn as sns # plot f, axes = plt.subplots(6, 6,
df = pd.DataFrame(np.random.randint(0,100,size=(100, 36)), columns=range(0,36))
我的代码:
import seaborn as sns
# plot
f, axes = plt.subplots(6, 6, figsize=(20, 20), sharex=True)
for feature in df.columns:
sns.distplot(df[feature] , color="skyblue", ax=axes[0, 0])
我想同时在轴和特征上循环是有意义的
f, axes = plt.subplots(6, 6, figsize=(20, 20), sharex=True)
for ax, feature in zip(axes.flat, df.columns):
sns.distplot(df[feature] , color="skyblue", ax=ax)
Numpy阵列按行展平,即第一行中的前6个特征、第二行中的6到11个特征等
如果这不是您想要的,您可以手动定义轴阵列的索引
f, axes = plt.subplots(6, 6, figsize=(20, 20), sharex=True)
for i, feature in enumerate(df.columns):
sns.distplot(df[feature] , color="skyblue", ax=axes[i%6, i//6])
e、 g.上述内容将逐列填充子图。
ax=轴[0,0]
意味着您将始终绘制到第一个轴。这也是你观察到的。也许你想画不同的坐标轴?哦,没错。我应该如何改变它?