我正在使用后端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保存数字,任何人都可以帮助我吗?