Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib crashing Python

I'm new to Python and matplotlib. A simple script I wrote is crashing 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()

The error is python.exe has stopped working. If I uncomment the plt.show(), it still crashes depending on the order I close the plots (no crash if 2 is closed first, crash if 1 is closed first). I'm using Windows 7, Python 3.4, and I installed the individual modules from www.lfd.uci.edu/~gohlke/pythonlibs/. Do I have something configured incorrectly or a misunderstanding of how to use matplotlib?

like image 715
vzaretsk Avatar asked Nov 16 '14 07:11

vzaretsk


Video Answer


1 Answers

You need to set the TkAgg backend explicitly. With the following code, the problem is resolved.

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

Note that setting the TkAgg backend after importing pyplot does not work either; it crashes too. You need to set it before importing pyplot.

like image 152
Luis B Avatar answered Sep 28 '22 04:09

Luis B