loop over 2d subplot as if it's a 1-D

前端 未结 2 1287
攒了一身酷
攒了一身酷 2021-02-20 06:33

I\'m trying to plot many data using subplots and I\'m NOT in trouble but I\'m wondering if there is a convenience method to do this.

below is the sample code.

         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-20 06:40

    subplots returns an ndarray of axes objects, you can just flatten or ravel it:

    fig, axes = plt.subplots(nrows = nrow, ncols=ncol, figsize=(8,6))
    for ax in axes.flatten()[:20]:
        # do stuff to ax
    

提交回复
热议问题