代码之家  ›  专栏  ›  技术社区  ›  maximusdooku

如何在循环中生成seaborn分发子批次?

  •  1
  • maximusdooku  · 技术社区  · 8 年前

    我有一个5D数组,叫做 data

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

    但我想把它们放在子地块里。我怎么做?

    我试过这个:

    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()
    

    2 回复  |  直到 8 年前
        1
  •  14
  •   ImportanceOfBeingErnest    8 年前

    您可能想使用 ax 海伯恩之争 distplot 函数为其提供现有轴。通过在轴的扁平阵列上循环,可以简化循环。

    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()
    
        2
  •  -1
  •   Tim    8 年前

    distplot 应落在:

    f = plt.figure()
    for i in range(10):
        f.add_subplot(4, 3, i+1)
        sns.distplot(data[i,0,0,0], hist=False)
    plt.show()