首页 > 解决方案 > 关闭、打开、枚举绘图 - 在 python matplotlib 中

问题描述

使用 spyder 和 Python 3.7

我使用此代码绘制图形:

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 1100, 1)
y = np.sin(2 * x * np.pi / 180)

fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_title('A single plot')

当我一次又一次地运行该程序时,它每次运行都会打开一个新图形。我想要的是能够在再次绘制之前关闭一个特定的图形。像这样的东西:

fig = fig(1)
plt.close(fig(1))
...create new fig...
plt.open(fig(1))    
plt.show()

但是上面是错误的, plt.show() 没有效果。

这看起来很简单——它不起作用。

标签: python-3.xmatplotlibspyder

解决方案


推荐阅读