该脚本在for循环中运行,每次迭代调用plt.plot()
,在循环调用之后plt.show()
-崩溃(屏幕冻结,需要强制重新启动)。崩溃之前或之后均未显示错误消息。 IMO,这不是内存问题。
与从shell / PyCharm IDE运行脚本相同。
有趣的观点:
我尝试跟踪许多其他已报告的问题here,here和here-均未成功。
MacOS版本:Mojave 10.14.6
我无法共享代码和数据,但为了轻松重现该问题-尝试运行以下简单代码:
>>> import matplotlib
>>> matplotlib.use("TkAgg")
>>> from matplotlib import pyplot as plt
>>> plt.plot(range(10))
[<matplotlib.lines.Line2D object at 0x1141069e8>]
>>> plt.show()
Mac崩溃(冻结并需要重新启动)。
包装:
matplotlib 3.0.3 py37h54f8f79_0
numpy 1.16.2 py37hacdab7b_0
numpy-base 1.16.2 py37h6575580_0
pyqt 5.9.2 py37h655552a_2
pyqt5 5.13.0 pypi_0 pypi
scikit学习0.20.3 py37h27c97d8_0
scipy 1.2.1 py37h1410ff5_0
*conda info*
active environment : base
active env location : /Users/nancy/anaconda3
shell level : 1
user config file : /Users/nancy/.condarc
populated config files : /Users/nancy/.condarc
**conda version : 4.7.11**
conda-build version : 3.17.8
**python version : 3.7.3.final.0**
virtual packages :
base environment : /Users/nancy/anaconda3 (writable)
channel URLs : http://statgen.org/wp-content/uploads/Softwares/pyplink/osx-64
http://statgen.org/wp-content/uploads/Softwares/pyplink/noarch
https://repo.anaconda.com/pkgs/main/osx-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/osx-64
https://repo.anaconda.com/pkgs/r/noarch
package cache : /Users/nancy/anaconda3/pkgs
/Users/nancy/.conda/pkgs
envs directories : /Users/nancy/anaconda3/envs
/Users/nancy/.conda/envs
**platform : osx-64**
**user-agent : conda/4.7.11 requests/2.21.0 CPython/3.7.3 Darwin/18.7.0 OSX/10.14.6**
UID:GID : 501:20
netrc file : None
offline mode : False
答案 0 :(得分:2)
根据ImportanceOfBeingErnest的评论,Apple不喜欢Tkinter(TkAgg后端),因此我需要将后端更改为“ Qt5Agg”
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib import pyplot as plt