Reputation: 2246
The script runs in a for loop, every iteration calls plt.plot()
and after looping calls plt.show()
- and crashes (screen freezes and need to force restart). No error message is presented before or after crashing. IMO, this is not a memory issue.
Same if I run the script from shell / PyCharm IDE.
INTERESTING POINTS:
I've tried following many other reported issues here, here, and here - with no success.
MacOS version: Mojave 10.14.6
I can't share the code and the data, but to easily reproduce the problem - try running this simple code:
>>> import matplotlib
>>> matplotlib.use("TkAgg")
>>> from matplotlib import pyplot as plt
>>> plt.plot(range(10))
[<matplotlib.lines.Line2D object at 0x1141069e8>]
>>> plt.show()
And the Mac crushes (freezes and need restart).
Packages:
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-learn 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
Upvotes: 6
Views: 5644
Reputation: 2246
According to ImportanceOfBeingErnest comment, Apple doesn't like Tkinter (TkAgg backend) so I needed to change the backend to 'Qt5Agg'
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib import pyplot as plt
Upvotes: 15