Aivar
Aivar

Reputation: 7052

How to get subplots of matplotlib Figure?

I know that I can use plt.subplots() to get handles for Figure and subplots at the same time, but how to get all subplots (or specific subplot) of an existing Figure instance?

Upvotes: 16

Views: 21005

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339705

If figure is a Figure instance you can get the axes inside it via

allaxes = fig.get_axes()

The return of this (allaxes) is a list of all the axes inside the figure. Which subplot is which in this list, you need to know from the figure or some other source.

Upvotes: 21

Related Questions