Python 的 matplotlib 图形构造函数如何处理这个数字?

What does Python's matplotlib figure constructor do with this number?

我目前使用的代码如下:

import matplotlib.pyplot as plt

fig = plt.figure(1)

我的问题如下:“1”是什么意思?我假设它是某种索引,但是 documentation 没有这个参数:

class matplotlib.figure.Figure(figsize=None, dpi=None, facecolor=None, edgecolor=None, linewidth=0.0, frameon=None, subplotpars=None, tight_layout=None)

我错过了什么吗?我很确定我不是第一个问这个问题的人,但是搜索和 "Questions that may already have your answer" 都没有给我答案...

我应该为我绘制的下一个数字增加这个值吗?

您需要查看您正在使用的命令的文档,而不是其他命令。

matplotlib.pyplot.figure(num=None, figsize=None, dpi=None,...) 有一个 num 参数。

num : integer or string, optional, default: none
If not provided, a new figure will be created, and the figure number will be incremented. The figure objects holds this number in a number attribute. If num is provided, and a figure with this id already exists, make it active, and returns a reference to it. If this figure does not exists, create it and returns it. If num is a string, the window title will be set to this figure’s num.

您不需要使用它,连续调用 plt.figure() 将自动创建新图形。