如何在循环中制作seaborn分布子图? [英] How can I make seaborn distribution subplots in a loop?

查看:96
本文介绍了如何在循环中制作seaborn分布子图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 data

for i in range(10):
     sns.distplot(data[i,0,0,0], hist=False)

但我想把它们放在子图中.我该怎么办?

But I want to make them inside subplots instead. How can I do it?

尝试过:

plt.rc('figure', figsize=(4, 4))  
fig=plt.figure()
fig, ax = plt.subplots(ncols=4, nrows=3)

for i in range(10):
    ax[i].sns.distplot(data[i,0,0,0], hist=False)
plt.show()

这显然行不通.

推荐答案

您可能想使用seaborn的 distplot 函数的 ax 参数为轴提供现有轴它.可以通过在平坦的轴阵列上循环来简化循环.

You would want to use the ax argument of the seaborn distplot function to supply an existing axes to it. Looping can be simplified by looping over the flattened array of axes.

fig, axes = plt.subplots(ncols=4, nrows=3)

for i, ax in zip(range(10), axes.flat):
    sns.distplot(data[i,0,0,0], hist=False, ax=ax)
plt.show()

这篇关于如何在循环中制作seaborn分布子图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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