您好我正在尝试从下面的链接添加matplotlib图表示例
Embedding a matplotlib figure inside a WxPython panel
使用WXGlade生成的wxpython框架内的面板。面板是panel_22,需要图表。任何建议?
#!/usr/bin/env python
# -*- coding: CP1252 -*-
#
# generated by wxGlade 0.6.8 (standalone edition) on Thu Jul 31 22:23:21 2014
#
import wx
# begin wxGlade: dependencies
import gettext
# end wxGlade
# begin wxGlade: extracode
# end wxGlade
class MyFrame1(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame1.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.panel_22 = wx.Panel(self, wx.ID_ANY)
self.__set_properties()
self.__do_layout()
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame1.__set_properties
self.SetTitle(_("frame_2"))
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame1.__do_layout
sizer_21 = wx.BoxSizer(wx.VERTICAL)
grid_sizer_4 = wx.GridSizer(3, 3, 0, 0)
grid_sizer_4.Add(self.panel_22, 1, wx.EXPAND, 0)
sizer_21.Add(grid_sizer_4, 1, wx.EXPAND, 0)
self.SetSizer(sizer_21)
sizer_21.Fit(self)
self.Layout()
# end wxGlade
# end of class MyFrame1
if __name__ == "__main__":
gettext.install("app") # replace with the appropriate catalog name
app = wx.App(False)
wx.InitAllImageHandlers()
frame_2 = MyFrame1(None, wx.ID_ANY, "")
app.SetTopWindow(frame_2)
frame_2.Show()
app.MainLoop()
答案 0 :(得分:0)
它是否在林间空地中产生似乎并不重要。所以试试
首先添加两个导入
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
然后在__do_layout的开头添加两行:
def __do_layout(self):
self.figure = Figure()
self.canvas = FigureCanvas(self,panel_22, -1, self.figure)
# begin wxGlade: MyFrame1.__do_layout