Python 如何在wxagg后端使用FigureCanvas保存matplotlib图形

Python 如何在wxagg后端使用FigureCanvas保存matplotlib图形,python,matplotlib,wxpython,backend,Python,Matplotlib,Wxpython,Backend,我正在使用后端AGG创建可以嵌入wx应用程序的画布,但我不知道如何使用FigureCanvas保存图形,以下是代码: import wx import matplotlib matplotlib.use("WXAgg") ## switching to wxAgg backend ## import matplotlib.pyplot as plt from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureC

我正在使用后端AGG创建可以嵌入wx应用程序的画布,但我不知道如何使用FigureCanvas保存图形,以下是代码:

import wx
import matplotlib
matplotlib.use("WXAgg") ## switching to wxAgg backend ##
import matplotlib.pyplot as plt
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas   
from matplotlib.figure import Figure
class MPL_Panel(wx.Panel):
    def __init__(self, parent):
      wx.Panel.__init__(self, parent=parent, id=-1,pos=(135,70),size=(390,300))
      self.Figure = matplotlib.figure.Figure(figsize=(4, 3))
      self.axes = self.Figure.add_axes([0.15, 0.15, 0.7, 0.7])
      self.FigureCanvas = FigureCanvas(self, -1, self.Figure)
class MyMenu(wx.Frame):
    def __init__(self, parent, id, title):
      wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(1100, 500))
      self.MPL = MPL_Panel(self)
      self.Figure = self.MPL.Figure
      self.axes = self.MPL.axes
      self.FigureCanvas = self.MPL.FigureCanvas
    def OnSave(self, event):
      global donnee
      self.Figure.savefig('foo.pdf')


    def Onplota(self):
 #list of x2,y2, because this part doesn't important, I just plot the line and it shows in my interface by using wxpython and matplotlib
    self.axes.plot(x2, y2, '.--')
    self.axes.hold
    self.axes.grid()
    #Render the figure using agg
    self.FigureCanvas.draw()

所以问题是,我想用agg保存图形,有人能帮我吗?

我根本看不到发布的代码是如何工作的。我只是选择代码中的一部分进行解释,因为我的问题集中在这一部分,所以我没有放完整的代码。这是很好的工作代码:我看不到发布的代码是如何工作的,完全有效。我只是选择代码中的一部分来解释,我没有把整个代码放进去,因为我的问题集中在这一部分。这是一个很好的工作代码: