How to get a list of axes for a figure in pyplot?

Question:

I am new to python and pyplot. I am trying to understand the documentation for the Matplotlib API related to the Figure Figure API.

In the beginning it says there is a class matplotlib.figure.AxesStack, and then

The AxesStack is a callable, where ax_stack() returns the current axes

When I try to use this in a program

import numpy as np
import matplotlib.pyplot as plt

n=4
v=np.arange(n)
X,Y = np.meshgrid(v,v)
Z=np.random.rand(n-1,n-1)

fig, ax = plt.subplots()
plt.pcolormesh(X, Y, Z)
plt.axis('tight')
plt.colorbar()
ast=fig.ax_stack()

plt.show()

I get error

AttributeError: 'Figure' object has no attribute 'ax_stack'
Asked By: Håkon Hægland

||

Answers:

The property axes returns a list of the Axes objects in the Figure object:

ax_list = fig.axes

(doc)

Answered By: tacaswell
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.