matplotlib图,然后等待原始输入 [英] matplotlib plot and then wait for raw input
问题描述
我正在尝试打开一系列.png图.我希望能够在屏幕上查看图,然后得到提示,等待我按Enter".按下Enter键后,应显示下一个图.我已经看到许多与此类似的问题( Matplotlib-Force绘图显示,然后返回主代码),但是当我这样做时,我必须手动单击绘图窗口右上角的X以将其关闭,然后代码才能继续.
I am trying to open a series of .png plots. I want to be able to view a plot on the screen and then get a prompt waiting for me to 'press enter'. On hitting enter, the next plot should be shown. I have seen many questions similar to this (Matplotlib - Force plot display and then return to main code) but when I do this I then have to manually click X on the top right-hand-side of the plot window to close it and only then does the code continue.
我正在使用python 2.7.8
I am using python 2.7.8
这是我的代码:
from PIL import Image
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import string
import sys
import shutil
fig=plt.figure()
Viewingfile = sys.argv[1]
for test_file in open(Viewingfile, "r").readlines():
fig.set_tight_layout(True)
plt.ion()
image=mpimg.imread(test_file + ".ps.png")
ax = fig.add_subplot(1, 1, 1)
imgplot = plt.imshow(image)
plt.show()
print test_file
a = raw_input('Next plot?\n')
if a == "1":
print "Do something..I've skipped these details"
plt.clf()
plt.close()
推荐答案
With recent version of matplotlib, you can use the call plt.show(block=False)
to open the matplotlib window non-blocking.
这篇关于matplotlib图,然后等待原始输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!