Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关闭嵌入Seaborn plot的wxpython面板_Python_Wxpython_Seaborn - Fatal编程技术网

关闭嵌入Seaborn plot的wxpython面板

关闭嵌入Seaborn plot的wxpython面板,python,wxpython,seaborn,Python,Wxpython,Seaborn,我在wxPython面板上装饰了一块seaborn地块,如下所示: self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) def OnCloseWindow(self,event): self.Destroy() 这是我为实现这一点而编写的代码: import numpy as np import seaborn as sns from matplotlib.backends.backend_wxagg import

我在wxPython面板上装饰了一块seaborn地块,如下所示:

        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

    def OnCloseWindow(self,event):
        self.Destroy()

这是我为实现这一点而编写的代码:

import numpy as np
import seaborn as sns
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
import wx

class SimplePanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        sns.set(style="whitegrid", palette="pastel", color_codes=True)
        self.figure = Figure()
        self.ax = self.figure.add_subplot(111)

        self.planets = sns.load_dataset("planets")

        self.years = np.arange(2010, 2014)
        sns.factorplot(x="year", ax= self.ax,data=self.planets, kind="count",palette="BuPu", size=6, aspect=1.5, order=self.years)
        sns.despine(left=True)

        self.canvas = FigureCanvas(self, -1, self.figure)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        self.SetSizer(self.sizer)
        self.Fit()


if __name__ == "__main__":
    app = wx.App(False)
    fr = wx.Frame(None, title='test', size=(800,600))
    panel = SimplePanel(fr)
    fr.Show()
    app.MainLoop()
问题:它工作正常,除非我关闭窗口,程序不会终止。我认为这与seaborn情节有关,因为我在没有它的情况下运行程序,程序正常关闭。但我不知道如何修复它。我还尝试过使用窗口的关闭功能(如下
self.Fit()
line):

        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

    def OnCloseWindow(self,event):
        self.Destroy()
但它也不起作用


有什么建议吗?

在销毁窗口之前删除seaborn plot对象。

您是否尝试过
plt.close()
?是的@Phlya我也尝试过,它也不起作用