Matplotlib: Error in sys.exitfunc

I keep getting error in sys.exitfunc when working with matplotlib. For example, the following code drop it for matplotlib 1.3.0 / Python 2.7.3 / Ubuntu 12.04.3 LTS

 from matplotlib.pyplot import figure, show from numpy.random import random fh = figure(figsize = (15, 10, )) ax = fh.add_axes((.1, .1, .8, .8, )) ax.scatter(random((100, )), random((100, ))) fh.show() 

This gives

 Error in atexit._run_exitfuncs: Traceback (most recent call last): File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "/usr/local/lib/python2.7/dist-packages/matplotlib/_pylab_helpers.py", line 86, in destroy_all manager.destroy() File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_gtk3.py", line 427, in destroy self.canvas.destroy() AttributeError: FigureManagerGTK3Agg instance has no attribute 'canvas' Error in sys.exitfunc: Traceback (most recent call last): File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "/usr/local/lib/python2.7/dist-packages/matplotlib/_pylab_helpers.py", line 86, in destroy_all manager.destroy() File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_gtk3.py", line 427, in destroy self.canvas.destroy() AttributeError: FigureManagerGTK3Agg instance has no attribute 'canvas' 

This happens at any time when the program ends without show() , including when an unrelated error occurs.

If I use show() instead of fh.show() , I do not get this error. I could just do it, but this error appears in many places, and I prefer to just solve it (and I want you to be able to exit without showing a number).

I tried other backends that are either inaccessible, or do not show, or give the same error (this is GKT3Agg).

+6
source share
5 answers

I had the same error. Using matplotlib.pyplot.close () at the end of my program, this is fixed. Maybe this works for you?

+4
source
 plt.plot(return_array, risk_array) plt.title('Pareto Front for '+ r'$\lambda \in$ [0.0, 1.0]') plt.xlabel('Return') plt.ylabel('Risk') plt.axis([0.02, 0.05, 0.01, 0.016]) 

only using the above code gives an error but adds

 matplotlib.pyplot.show() 

at the end works for me

+1
source

dowload matplotlib-1.3.1.tar.gz from http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.3.1/

 cd matplotlib-1.3.1 sudo python setup.py install 

before that install the following

 sudo apt-get install libfreetype6-dev sudo apt-get install python-dev sudo apt-get install libevent-dev sudo apt-get install libpng-dev 
0
source

I had the same error and the ShikharDua solution solved the problem for me. My system: ubuntu 13.10 64 bit.

I wanted to run sample code that did not call the plt.show() function at the end, resulting in: AttributeError: FigureManagerGTK3Agg instance has no attribute 'canvas'

Interestingly, the same code without plt.show() worked in ipython if pylab had been called pylab .

edit: Well, I just read that you already mentioned this in your question. Therefore, this is not a solution for you. However, this is a solution for beginners who have wondered why some code examples do not work.

0
source

This is my terrible hack to get around it:

  import matplotlib.pyplot as plt # your use of matplotlib here where you don't use the plot.show() function try: plt.close() except AttributeError, e: pass 
0
source

Source: https://habr.com/ru/post/954917/


All Articles