Matplotlib - Tcl_AsyncDelete: async handler deleted by the wrong thread?

前端 未结 3 1792
暖寄归人
暖寄归人 2020-12-14 07:42

I\'m asking this question because I can\'t solve one problem in Python/Django (actually in pure Python it\'s ok) which leads to RuntimeError: tcl_asyncdel

3条回答
  •  失恋的感觉
    2020-12-14 07:58

    The above (accepted) answer is a solution in a terminal environment. If you debug in an IDE, you still might wanna use 'TkAgg' for displaying data. In order to prevent this issue, apply these two simple rules:

    1. everytime you display your data, initiate a new fig = plt.figure()
    2. don't close old figures manually (e.g. when using a debug mode)

    Example code:

    import matplotlib
    matplotlib.use('TkAgg')
    from matplotlib import pyplot as plt
    
    fig = plt.figure()
    plt.plot(data[:,:,:3])
    plt.show()
    

    This proves to be the a good intermediate solution under MacOS and PyCharm IDE.

提交回复
热议问题