简体   繁体   中英

Matplotlib exception in Tkinter callback after window resize

I have problem with pyplot window. When I try to change window size after ploting is done I get the following exception:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1532, in __call__
    return self.func(*args)
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 277, in resize
    self.resize_event()
  File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line 1788, in resize_event
    self.callbacks.process(s, event)
  File "C:\Python27\lib\site-packages\matplotlib\cbook.py", line 540, in process
    proxy(*args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\cbook.py", line 415, in __call__
    return mtd(*args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 859, in _handle_resize
    self._init_draw()
  File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 1077, in _init_draw
    self._draw_frame(next(self.new_frame_seq()))
StopIteration

Ploting is done by:

self.ani = animation.FuncAnimation(self.fig, self._set_data, self._is_running(), interval=20, repeat=False, blit=True)
plt.show()

When ploting is done everything is ok. After maximizing window, exception is thrown, window is maximized but its all grey (no plot). Then I change its size again and everything goes back to normal and plot is drawn. Can someone point me whats wrong or where to look for answer?

OS: Windows 7
Python: 2.9 32b
Matplotlib ver: 1.4.2, backend: TkAgg

I had a similar problem (on Fedora), while working with a large amount of data. But with diferent error: OverflowError: In draw_path: Exceeded cell block limit . I had the same error saving the image with high dpi resolution, as plt.savefig('example.png', dpi=282) . No error with low dpi parameter.

I found a solution to my problem in: https://github.com/matplotlib/matplotlib/issues/5907

So, the basic answer is:

Try:

import matplotlib as mpl
mpl.rcParams['agg.path.chunksize'] = 10000 # the default is 0

You can change it in matplotlibrc file to make it default. You can find your matplotlibrc location with:

matplotlib.matplotlib_fname()

then you can change agg.path.chunksize parameter uncommenting the line and setting the new default value:

agg.path.chunksize : 10000

http://matplotlib.org/users/customizing.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM