gpt4 book ai didi

python - 清除 MatPlotLib 中的特定图形

转载 作者:太空宇宙 更新时间:2023-11-04 00:35:50 24 4
gpt4 key购买 nike

在 MatPlotLib 中,我可以使用:

plt.gcf().clear()

清除当前图形的内容。

但假设我有两个图形,创建时使用:

fig1 = plt.figure(1)
fig2 = plt.figure(2)

如何根据数字清除特定数字?

最佳答案

.clear() 是图形类的一个方法。通过 plt.gcf() 或通过存储它的变量获取 matplotlib.figure.Figure 实例并不重要。因此

fig1.clear()

将清除存储在 fig1 中的图形。

当然你也可以直接调用plt.figure()来清除那个数字,

plt.figure(1).clear()

关于python - 清除 MatPlotLib 中的特定图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44075145/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com