我有一个脚本可以绘制一些测光孔径的数据,我想将它们绘制在 xy 图中。我在 python 2.5 中使用 matplotlib.pyplot。
输入数据存储在大约 500 个文件中并被读取。我知道这不是输入数据的最有效方式,但这是另一个问题......
示例代码:
import matplotlib.pyplot as plt
xcoords = []
ycoords = []
# lists are populated with data from first file
pltline, = plt.plot(xcoords, ycoords, 'rx')
# then loop populating the data from each file
for file in filelist:
xcoords = [...]
ycoords = [...]
pltline.set_xdata(xcoords)
pltline.set_ydata(ycoords)
plt.draw()
由于有超过 500 个文件,我偶尔会想在绘图中间关闭动画窗口。我的绘图代码有效,但它并没有非常优雅地退出。绘图窗口对单击关闭按钮没有响应,我必须Ctrl+C
退出它。
谁能帮我找到一种在脚本运行时关闭动画窗口的方法,同时看起来很优雅(比一系列 python 回溯错误更优雅)?