Python 如何在pyplot中获取图形的轴列表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24104990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 03:59:09  来源:igfitidea点击:

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

pythonmatplotlib

提问by H?kon H?gland

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

我是python和 的新手pyplot。我试图了解与 Figure Figure API相关的 Matplotlib API 的文档。

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

一开始它说有一个class matplotlib.figure.AxesStack,然后

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

AxesStack 是可调用的,其中 ax_stack() 返回当前轴

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'

采纳答案by tacaswell

The property axesreturns a list of the Axesobjects in the Figureobject:

该属性axes返回Axes对象中的Figure对象列表:

ax_list = fig.axes

(doc)

(文档)