目前我试图让自己熟悉 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/