在 Python 中,可以使用 matplotlib.pyplot.figure() 函数来创建一个新的 figure,并使用 figure() 函数中的 num 参数指定 figure 的编号。默认情况下,figure 的编号是递增的。

要在新的 figure 上绘制图形,可以使用 matplotlib.pyplot.plot() 或其他绘图函数。在绘制完图形后,可以使用 matplotlib.pyplot.show() 函数来显示图形。

下面是一个示例代码,展示了如何创建一个新的 figure 并绘制图形,而不影响之前的几个 figure:

import matplotlib.pyplot as plt

# 创建第一个 figure 并绘制图形
plt.figure(1)
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])

# 创建第二个 figure 并绘制图形
plt.figure(2)
plt.plot([1, 2, 3, 4], [1, 8, 27, 64])

# 创建第三个 figure 并绘制图形
plt.figure(3)
plt.plot([1, 2, 3, 4], [1, 16, 81, 256])

# 显示所有的 figure
plt.show()

在上述示例代码中,我们分别创建了三个 figure,并在每个 figure 上绘制了不同的图形。在最后调用 plt.show() 函数时,将显示所有的 figure。


原文地址: https://www.cveoy.top/t/topic/pidU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录