如何从多个图中删除 matplotlib 轴?

How to remove matplotlib axis from multiple plots?

我有多个子图,但我似乎无法从所有图中删除轴,只能删除其中一个。执行此操作的最佳方法是什么?

import numpy as np
import matplotlib.pyplot as plt

array_list = [np.random.random_integers(0, i, (5,5)).astype(bool) for i in range(10)]

count = 0    
fig, axes = plt.subplots(nrows=2, ncols=5)
for i in range(2):
    for j in range(5):
        axes[i, j].imshow(array_list[count], interpolation='nearest')
        count += 1
plt.axis('off')
plt.show()

您需要为每个子图关闭轴。试试下面的代码,看看是不是你想要的。

import numpy as np
import matplotlib.pyplot as plt

array_list = [np.random.random_integers(0, i, (5,5)).astype(bool) for i in range(10)]

count = 0    
fig, axes = plt.subplots(nrows=2, ncols=5)
for i in range(2):
    for j in range(5):
        axes[i, j].imshow(array_list[count], interpolation='nearest')
        count += 1
        axes[i, j].axis('off')
plt.show()