plt.subplots中的ax = ax.flatten()
生活随笔
收集整理的這篇文章主要介紹了
plt.subplots中的ax = ax.flatten()
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在用plt.subplots畫多個子圖中,ax = ax.flatten()將ax由n*m的Axes組展平成1*nm的Axes組
以下面的例子說明ax = ax.flatten()的作用:
fig, ax = plt.subplots(nrows=2,ncols=2,sharex='all',sharey='all') ax = ax.flatten() for i in range(4):img = image[i].reshape(28, 28)ax[i].imshow(img, cmap='Greys', interpolation='nearest') # 區別:可以直接用ax[i]不使用ax = ax.flatten()
fig, ax = plt.subplots(nrows=2,ncols=2,sharex='all',sharey='all') for i in range(4):img = image[i].reshape(28, 28)axs[0, 0].imshow(img, cmap='Greys', interpolation='nearest') # 區別:不能直接使用ax[i]axs[0, 1].imshow(img, cmap='Greys', interpolation='nearest')axs[1, 0].imshow(img, cmap='Greys', interpolation='nearest')axs[1, 1].imshow(img, cmap='Greys', interpolation='nearest')?
總結
以上是生活随笔為你收集整理的plt.subplots中的ax = ax.flatten()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 截高清图软件
- 下一篇: 将联网方式更改为桥接模式