下面是我试图执行的代码。
x = np.random.normal(size=1000)
fig, ax = plt.subplots()
H = ax.hist(x, bins=50, alpha=0.5, histtype='stepfilled')
谁能详细说明 fig, ax = plt.subplots() 在这里做什么?
谢谢你。
下面是我试图执行的代码。
x = np.random.normal(size=1000)
fig, ax = plt.subplots()
H = ax.hist(x, bins=50, alpha=0.5, histtype='stepfilled')
谁能详细说明 fig, ax = plt.subplots() 在这里做什么?
谢谢你。
正如你可以从这里读到的
plt.subplots()
是一个函数,它返回一个包含图形和坐标区对象的元组。因此,当您使用时fig, ax = plt.subplots()
将此元组解包到变量fig
和ax
.fig
如果您想更改图形级别的属性或稍后将图形保存为图像文件(例如,使用.fig.savefig('yourfilename.png')
您当然不必使用返回的图形对象,但很多人稍后会使用它,因此它很常见,因此很有用。此外,所有坐标区对象(具有绘图方法的对象)都有一个父图形对象。
该参数bins
用于设置用于在这些范围内累积数据的范围数。我不知道你还有什么问题。