【发布时间】:2016-10-05 03:19:43
【问题描述】:
我有以下代码,它采用对象列表,并为每个对象从对象中存储的数据中绘制一个图形:
def Plot(self, *figures , wait = True):
def plot(fig,n):
fig.fig = plt.figure(n)
print("Ploting figure {} for file {}\n".format(n,fig.name))
fig.Plot()
plt.show()
if wait:
input("Press Enter to continue to next figure")
if not figures:
figures = self.figures
for n,fig in figures.items():
plot(fig,n)
else:
for n,fig in enumerate(figures):
plot(fig,n)
fig.Plot() 是处理绘图的函数。运行“绘图”时,循环的每次迭代都会生成一个图形,但实际绘制仅在循环完成后发生。
我想要实现的是,在每次迭代中都会生成图形并在继续下一次迭代之前绘制绘图。
【问题讨论】:
-
经过一番谷歌搜索后,我在physicalmodelingwithpython.blogspot.co.il/2015/07/… 找到了一个解决方案,其中行:“if wait: input("Press Enter to continue to next figure")”应替换为:“while True : if plt.waitforbuttonpress(): break"
-
请发表您的评论作为答案。
标签: python loops matplotlib plot iteration