我创建并运行了一个非常简单的python代码来显示直方图。直方图显示成功,但程序永远不会完成。你能帮忙吗?
单击Ctrl和C,将显示以下消息。
File "hist_ex.py", line 9, in <module>
plt.show()
File "/Users/myusername/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/matplotlib/pyplot.py", line 254, in show
return _show(*args, **kw)
File "/Users/myusername/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 218, in show
cls.mainloop()
File "/Users/myusername/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages/matplotlib/backends/backend_tkagg.py", line 1078, in mainloop
Tk.mainloop()
File "/Users/myusername/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/tkinter/__init__.py", line 557, in mainloop
_default_root.tk.mainloop(n)
KeyboardInterrupt
这是我的python代码。
import numpy as np
import matplotlib.pyplot as plt
x = np.random.normal(50, 10, 1000)
plt.hist(x)
plt.show()
答案 0 :(得分:0)
这种情况正在发生,因为您处于非交互模式......
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.show.html
尝试使用
plt.show(block=False)