kezzos
kezzos

Reputation: 3221

How to remove matplotlib axis from multiple plots?

I have multiple subplots but I cant seem to remove the axis from all of the plots, only one of them. What is the best way to do this?

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

Upvotes: 0

Views: 1300

Answers (1)

pyan
pyan

Reputation: 3707

You need to turn off the axis for each subplot. Try the following code and see if it is what you want.

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

Upvotes: 2

Related Questions