In trying to do some small multiple stuff, I want to make a bunch of subplots with Matplotlib and toss in varying data to each. pyplot.subplots()
gives me a Figure
and Numpy array of Axes
, but in trying to iterate over the axes, I am stumped on how to actually get at them.
I'm trying something akin to:
import numpy as np
import matplotlib.pyplot as plt
f, axs = plt.subplots(2,2)
for ax in np.nditer(axs, flags=['refs_ok']):
ax.plot([1,2],[3,4])
However, the type of ax
in each iteration is not an Axes
, but rather an ndarray
, so attempting to plot fails with:
AttributeError: 'numpy.ndarray' object has no attribute 'plot'
How can I loop over my axes?