matplotlib - 子图的返回值

标签 matplotlib python-2.6

目前我试图让自己熟悉 matplotlib.pyplot 库。在看过相当多的例子和教程后,我注意到 subplots 函数也有一些返回值,这些值通常在以后使用。但是,在 matplotlib 网站上,我无法找到任何关于返回的确切内容的说明,并且没有一个示例是相同的(尽管它通常似乎是一个 ax 对象)。你们能给我一些关于返回什么以及我如何使用它的指示。提前致谢!

最佳答案

documentation它说 matplotlib.pyplot.subplots返回 Figure 的实例和一组(或单个) Axes (数组与否取决于子图的数量)。

常见的用途是:

import matplotlib.pyplot as plt
import numpy as np
f, axes = plt.subplots(1,2)  # 1 row containing 2 subplots.

# Plot random points on one subplots.
axes[0].scatter(np.random.randn(10), np.random.randn(10))

# Plot histogram on the other one.
axes[1].hist(np.random.randn(100))

# Adjust the size and layout through the Figure-object.
f.set_size_inches(10, 5)
f.tight_layout()

关于matplotlib - 子图的返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29644361/

相关文章:

python - 使用参数从 subprocess.call 调用应用程序

linux - 来自emacs的Ubuntu Linux python绘图,无法从 '_imaging'导入名称 'PIL'

python - sklearn.decomposition.PCA 特征向量的简单图

Python:为什么 DictWriter 写入 'NULL' 字节?

python - python 3 中的 Expat 解析

python - 检查元组中有多少个 child

python - 在 python 2.6 中创建字典的字典

python - 在 seaborn 中使用 Unicode 文本

python - 使用 matshow 在行和/或列之间插入间隙

python - 如何给 matplotlib slider 贴上标签?