我写了一个小脚本来批量绘制一些数据。如果没有显示新创建的绘图开放的窗口,则此脚本无法运行。它会停止运行,直到手动关闭窗口,然后脚本继续运行。所以我的问题如下:
有没有办法在python脚本中自动关闭输出窗口?
这是脚本
import pynbody
import numpy as np
import pynbody.plot.sph as sph
f = open('files.txt', 'r')
for line in f:
line = line[0:-1]
s = pynbody.load(line)
sph.image(s.gas,qty="temp",width=16, filename=line[0:-6]+line[-5:len(line)], units='K', cmap="YlOrRd", ret_im=False , approximate_fast=False)
#At the end of the loop I would like to close the output window so the script
#will continue to run
pynbody.plot.sph包看起来应该能够在sph.image函数调用中打开和关闭输出窗口,但我已经用尽所有可能性,现在我正在使用它来运行脚本。
答案 0 :(得分:1)
我使用此link
找到了答案view and then close the figure automatically in matplotlib?
基本上,这是答案:
<div class="container">
<div class="row">
<div class="col-md-12 p-2">
<img class="d-block mx-auto mx-md-0" src="//placehold.it/200" alt="">
</div>
</div>
</div>
答案 1 :(得分:0)
根据 documentation,您应该将noplot参数设置为True
答案 2 :(得分:0)
在for循环中添加一行 pynbody.plot.plt.close()。
定义:pynbody.plot.plt.close(* args)Docstring:关闭一个数字 窗口。
close()
本身会关闭当前数字
close(h)
其中 h 是:class:Figure
实例,关闭 图
close(num)
关闭图号 num
close(name)
其中 name 是一个字符串,用它关闭数字 标签
close('all')
关闭所有数字窗口