Prob using axes for subplot an get AttributeError: ‘numpy.ndarray’ object has no attribute ‘plot’

As you say, the problem is with this line:


In your code, axs is a 3×10 numpy array of AxesSubplot objects. I assume what you’re trying to do is to call the plot() method on several of those objects at once, but numpy arrays don’t support method calls like that. You could look at the vectorize() method, but I think it’s clearest to just use a for loop. Here’s a small example that calls plot() with some data on a couple of subplots, then calls plot() with no parameters on the rest of the subplots.

import matplotlib.pyplot as plt

fig, axs = plt.subplots(nrows=2,ncols=3)

axs[0, 0].plot([1, 4, 2])
axs[0, 2].plot([4, 1, 2])

# Could probably remove the next three lines.
axs[0, 1].plot()
for iii in range(3):
    axs[1, iii].plot()

I only wonder why you want to call plot() with no parameters in the first place. It just seems to change the axis scale a bit. Try removing those calls completely.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top