在过go 的几天里,我一直在玩Numpy和matplotlib.我在try 让matplotlib在不阻塞执行的情况下绘制函数时遇到了问题.我知道这里已经有很多帖子在问类似的问题,我已经用谷歌搜索了相当多,但都没能做到这一点.
我试过按照一些人的建议使用SHOW(挡路=FALSE),但是我得到的只是一个冻结的窗口.如果我简单地调用show(),结果会正确绘制,但执行会被阻止,直到窗口关闭.从我看过的其他帖子来看,我怀疑SHOW(挡路=FALSE)能不能运行取决于后台,对吗?我的后台是Qt4Agg,你能看一下我的代码告诉我有什么问题吗?这是我的代码,谢谢你的帮助.
from math import *
from matplotlib import pyplot as plt
print(plt.get_backend())
def main():
x = range(-50, 51, 1)
for pow in range(1,5): # plot x^1, x^2, ..., x^4
y = [Xi**pow for Xi in x]
print(y)
plt.plot(x, y)
plt.draw()
#plt.show() #this plots correctly, but blocks execution.
plt.show(block=False) #this creates an empty frozen window.
_ = raw_input("Press [enter] to continue.")
if __name__ == '__main__':
main()
另外,我忘了说我想在每次绘图时更新现有窗口,而不是创建一个新窗口.