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

前端 未结 3 1794
暖寄归人
暖寄归人 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:43

    If you don't need to show plots while debugging, the following works:

    import matplotlib
    matplotlib.use('Agg')
    from matplotlib import pyplot as plt
    

    However, if you would like to plot while debugging, you need to do 3 steps:

    1.Keep backend to 'TKAgg' as follows:

    import matplotlib
    matplotlib.use('TKAgg')
    from matplot.lib import pyplot as plt
    

    or simply

    import matplotlib.pyplot as plt
    

    2.As Fábio also mentioned, you need to add fig(no. #i)=plt.figure(no.#i) for each figure #i. As the following example for plot no.#1, add:

    fig1 = plt.figure(1)
    plt.plot(yourX,yourY)
    plt.show()
    

    3.Add breakpoints. You need to add two breakpoints at least, one somewhere at the beginning of your codes (before the first plot), and the other breakpoint at a point where you would like all plots (before to the second breakpoint) are plotted. All figures are plotted and you even don't need to close any figure manually.

提交回复
热议问题