matplotlib iterate subplot axis array through single list

前端 未结 6 1284
醉话见心
醉话见心 2020-12-13 04:08

Is there a simple/clean way to iterate an array of axis returned by subplots like

nrow = ncol = 2
a = []
fig, axs = plt.subplots(nrows=nrow, ncols=ncol)
for         


        
6条回答
  •  粉色の甜心
    2020-12-13 04:39

    The fig return value of plt.subplots has a list of all the axes. To iterate over all the subplots in a figure you can use:

    nrow = 2
    ncol = 2
    fig, axs = plt.subplots(nrow, ncol)
    for i, ax in enumerate(fig.axes):
        ax.set_ylabel(str(i))
    

    This also works for nrow == ncol == 1.

提交回复
热议问题