【发布时间】:2020-02-22 00:25:38
【问题描述】:
考虑以下代码:
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(19680801)
data = np.random.randn(2, 100)
fig, axs = plt.subplots(2, 2, figsize=(5, 5))
axs[0, 0].hist(data[0])
axs[1, 0].scatter(data[0], data[1])
axs[0, 1].plot(data[0], data[1])
axs[1, 1].hist2d(data[0], data[1])
plt.show()
我知道为了创建子图,您需要编写以下代码行:
fig, axs = plt.subplots(2, 2, figsize=(5, 5)
但是我的问题是关于这一行的含义,例如它通过生成变量 fig 和 axs 实际实现了什么,以及为什么稍后我们使用 ax[0,0] 而不是 fig[0,0]
【问题讨论】:
-
一个图包含4个轴?
标签: matplotlib histogram subplot fig