Matplotlib python crash

I am new to Python and matplotlib. A simple script I wrote crashed and I was able to reproduce the crash with the following code:

import matplotlib.pyplot as plt
plt.figure(1)
plt.figure(2)
#plt.show()

      

Error python.exe has stopped working

. If I uncomment plt.show () it still crashes depending on the order in which the closed portions are closed (no crash if 2 is closed first, crash if the first is closed). I am using Windows 7, Python 3.4 and I have installed individual modules from www.lfd.uci.edu/~gohlke/pythonlibs/. Am I misconfigured or misunderstood on how to use matplotlib?

+3


source to share


5 answers


You need to explicitly install the TkAgg backend. The following code resolves the problem.

import matplotlib
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt

      



Note that setting the TkAgg backend after importing pyplot also doesn't work; he also falls. You need to install it before importing pyplot.

+1


source


It might be a problem with python 3.x

I tried with python 2.7 on my windows machine and it works great!



You can either downgrade your python to 2.7 or if you feel like it's too late to do why not try calling close ()

Import matplotlib
matplotlib.use('wxAgg')
Import matplotlib.pyplot as plt
# your scripts
plt.close('all')

      

0


source


I had a similar problem on OSX when I upgraded to Python 3.4. IDLE was also crashing and there was a warning that the version was unstable.

I solved it by following the prompts and updating my Tcl / Tk version (8.5.9) - http://www.python.org/download/mac/tcltk .

0


source


I had this problem, I thought it was some line in my code causing an error, but actually the process of importing matplotlib.pyplot was killing my program. I solved it by first running it in verbose mode:

python -v [programname].py

This shows the last action the importer takes before the crash. For me, the last line of this was:

import 'PyQt5' # <_frozen_importlib_external.SourceFileLoader object at 0x000001F8EC9C0908>

This told me that the dependent library PyQt5

was causing problems, so I ran pip install PyQt5

it and it magically started working.

0


source


For macOS, just make sure

~ / .matplotlib / matplotlibrc contains:

backend: MacOSX

      

You don't need other backends unless you specifically want them. Alternatively, perhaps you can do:

import matplotlib
matplotlib.use("MacOSX")

      

although I haven't tested it.

0


source







All Articles